aboutsummaryrefslogtreecommitdiff
path: root/auth_sqlite3.go
diff options
context:
space:
mode:
Diffstat (limited to 'auth_sqlite3.go')
-rw-r--r--auth_sqlite3.go30
1 files changed, 20 insertions, 10 deletions
diff --git a/auth_sqlite3.go b/auth_sqlite3.go
index 8574768..4ad9724 100644
--- a/auth_sqlite3.go
+++ b/auth_sqlite3.go
@@ -9,11 +9,12 @@ import (
_ "github.com/mattn/go-sqlite3"
)
-type AuthSQLite3 struct {
+type authSQLite3 struct {
db *sql.DB
}
-func (a AuthSQLite3) Exists(name string) bool {
+// Exists reports whether a user is registered.
+func (a authSQLite3) Exists(name string) bool {
if err := a.init(); err != nil {
return false
}
@@ -24,7 +25,8 @@ func (a AuthSQLite3) Exists(name string) bool {
return err == nil
}
-func (a AuthSQLite3) Passwd(name string) (salt, verifier []byte, err error) {
+// Passwd returns the SRP salt and verifier of a user or an error.
+func (a authSQLite3) Passwd(name string) (salt, verifier []byte, err error) {
if err = a.init(); err != nil {
return
}
@@ -35,7 +37,9 @@ func (a AuthSQLite3) Passwd(name string) (salt, verifier []byte, err error) {
return
}
-func (a AuthSQLite3) SetPasswd(name string, salt, verifier []byte) error {
+// SetPasswd creates a password entry if necessary
+// and sets the password of a user.
+func (a authSQLite3) SetPasswd(name string, salt, verifier []byte) error {
if err := a.init(); err != nil {
return err
}
@@ -50,7 +54,9 @@ func (a AuthSQLite3) SetPasswd(name string, salt, verifier []byte) error {
return nil
}
-func (a AuthSQLite3) Timestamp(name string) (time.Time, error) {
+// Timestamp returns the last time an authentication entry was accessed
+// or an error.
+func (a authSQLite3) Timestamp(name string) (time.Time, error) {
if err := a.init(); err != nil {
return time.Time{}, err
}
@@ -65,7 +71,9 @@ func (a AuthSQLite3) Timestamp(name string) (time.Time, error) {
return time.Parse("2006-01-02 15:04:05", tstr)
}
-func (a AuthSQLite3) Import(in []user) {
+// Import clears the database and and refills it with the passed
+// users.
+func (a authSQLite3) Import(in []user) {
if err := a.init(); err != nil {
return
}
@@ -78,7 +86,9 @@ func (a AuthSQLite3) Import(in []user) {
}
}
-func (a AuthSQLite3) Export() ([]user, error) {
+// Export returns data that can be processed by Import
+// or an error.
+func (a authSQLite3) Export() ([]user, error) {
if err := a.init(); err != nil {
return nil, err
}
@@ -119,11 +129,11 @@ func (a AuthSQLite3) Export() ([]user, error) {
return out, nil
}
-func (a AuthSQLite3) updateTimestamp(name string) {
+func (a authSQLite3) updateTimestamp(name string) {
a.db.Exec(`UPDATE user SET timestamp = datetime("now") WHERE name = ?;`, name)
}
-func (a *AuthSQLite3) init() error {
+func (a *authSQLite3) init() error {
executable, err := os.Executable()
if err != nil {
return err
@@ -148,6 +158,6 @@ func (a *AuthSQLite3) init() error {
return nil
}
-func (a AuthSQLite3) close() error {
+func (a authSQLite3) close() error {
return a.db.Close()
}