]> git.r.bdr.sh - rbdr/mobius/blobdiff - hotline/account.go
Refactoring, cleanup, test backfilling
[rbdr/mobius] / hotline / account.go
index 18965ed5ea1b4a9ae5cb711eff4c0d181a11c255..7b2aafed09889a16a6b454036e844f4cd59083b6 100644 (file)
@@ -5,7 +5,6 @@ import (
        "fmt"
        "golang.org/x/crypto/bcrypt"
        "io"
        "fmt"
        "golang.org/x/crypto/bcrypt"
        "io"
-       "log"
        "slices"
 )
 
        "slices"
 )
 
@@ -20,6 +19,15 @@ type Account struct {
        readOffset int // Internal offset to track read progress
 }
 
        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{
 // 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 {
 
 // 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)
 }
 
        return string(hash)
 }