Move stuff to util.go

This commit is contained in:
binwiederhier
2025-07-31 07:33:11 +02:00
parent 23ec7702fc
commit b91ff5f0b5
6 changed files with 82 additions and 76 deletions

View File

@@ -1015,11 +1015,11 @@ func (a *Manager) addUserTx(tx *sql.Tx, username, password string, role Role, ha
var err error = nil
if hashed {
hash = password
if err := AllowedPasswordHash(hash); err != nil {
if err := ValidPasswordHash(hash); err != nil {
return err
}
} else {
hash, err = a.HashPassword(password)
hash, err = hashPassword(password, a.config.BcryptCost)
if err != nil {
return err
}
@@ -1365,11 +1365,11 @@ func (a *Manager) changePasswordTx(tx *sql.Tx, username, password string, hashed
var err error
if hashed {
hash = password
if err := AllowedPasswordHash(hash); err != nil {
if err := ValidPasswordHash(hash); err != nil {
return err
}
} else {
hash, err = a.HashPassword(password)
hash, err = hashPassword(password, a.config.BcryptCost)
if err != nil {
return err
}
@@ -1697,15 +1697,6 @@ func (a *Manager) readTier(rows *sql.Rows) (*Tier, error) {
}, nil
}
// HashPassword hashes the given password using bcrypt with the configured cost
func (a *Manager) HashPassword(password string) (string, error) {
hash, err := bcrypt.GenerateFromPassword([]byte(password), a.config.BcryptCost)
if err != nil {
return "", err
}
return string(hash), nil
}
// Close closes the underlying database
func (a *Manager) Close() error {
return a.db.Close()