]> git.r.bdr.sh - rbdr/mobius/blobdiff - hotline/account.go
Update docker image name
[rbdr/mobius] / hotline / account.go
index 3ad068797294c91e5b8e159a64364d0cdf77ac48..7b2aafed09889a16a6b454036e844f4cd59083b6 100644 (file)
@@ -5,7 +5,6 @@ import (
        "fmt"
        "golang.org/x/crypto/bcrypt"
        "io"
-       "log"
        "slices"
 )
 
@@ -15,11 +14,20 @@ type Account struct {
        Login    string       `yaml:"Login"`
        Name     string       `yaml:"Name"`
        Password string       `yaml:"Password"`
-       Access   accessBitmap `yaml:"Access"`
+       Access   accessBitmap `yaml:"Access,flow"`
 
        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{
@@ -57,10 +65,7 @@ func (a *Account) Read(p []byte) (int, error) {
 
 // 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)
-       }
+       hash, _ := bcrypt.GenerateFromPassword(pwd, bcrypt.MinCost)
 
        return string(hash)
 }