]> git.r.bdr.sh - rbdr/mobius/blobdiff - hotline/account.go
Fix missing version in Docker and Makefile build
[rbdr/mobius] / hotline / account.go
index 3ad068797294c91e5b8e159a64364d0cdf77ac48..526eb053b176a84b54d9d84b56ade12ac9e0a89f 100644 (file)
@@ -5,7 +5,6 @@ import (
        "fmt"
        "golang.org/x/crypto/bcrypt"
        "io"
-       "log"
        "slices"
 )
 
@@ -15,16 +14,26 @@ type Account struct {
        Login    string       `yaml:"Login"`
        Name     string       `yaml:"Name"`
        Password string       `yaml:"Password"`
-       Access   accessBitmap `yaml:"Access"`
+       Access   AccessBitmap `yaml:"Access,flow"`
+       FileRoot string       `yaml:"FileRoot"`
 
        readOffset int // Internal offset to track read progress
 }
 
+func NewAccount(login, name, password string, access AccessBitmap) *Account {
+       return &Account{
+               Login:    login,
+               Name:     name,
+               Password: HashAndSalt([]byte(password)),
+               Access:   access,
+       }
+}
+
 // Read implements io.Reader interface for Account
 func (a *Account) Read(p []byte) (int, error) {
        fields := []Field{
                NewField(FieldUserName, []byte(a.Name)),
-               NewField(FieldUserLogin, encodeString([]byte(a.Login))),
+               NewField(FieldUserLogin, EncodeString([]byte(a.Login))),
                NewField(FieldUserAccess, a.Access[:]),
        }
 
@@ -55,12 +64,9 @@ func (a *Account) Read(p []byte) (int, error) {
        return n, nil
 }
 
-// hashAndSalt generates a password hash from a users obfuscated plaintext password
-func hashAndSalt(pwd []byte) string {
-       hash, err := bcrypt.GenerateFromPassword(pwd, bcrypt.MinCost)
-       if err != nil {
-               log.Println(err)
-       }
+// HashAndSalt generates a password hash from a users obfuscated plaintext password
+func HashAndSalt(pwd []byte) string {
+       hash, _ := bcrypt.GenerateFromPassword(pwd, bcrypt.MinCost)
 
        return string(hash)
 }