X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/blobdiff_plain/95159e5585762c06c654945070ba54262b7dcec9..4d7abe62a6dd692b71090819de0d57a40486bdb2:/hotline/account.go diff --git a/hotline/account.go b/hotline/account.go index 3ad0687..7b2aafe 100644 --- a/hotline/account.go +++ b/hotline/account.go @@ -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) }