parent
20bc9fe17a
commit
4f68621bad
9 changed files with 126 additions and 42 deletions
|
@ -2,6 +2,7 @@ package model
|
|||
|
||||
import (
|
||||
"crypto/subtle"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.adyxax.org/adyxax/tfstated/pkg/helpers"
|
||||
|
@ -27,6 +28,17 @@ func (account *Account) CheckPassword(password string) bool {
|
|||
return subtle.ConstantTimeCompare(hash, account.PasswordHash) == 1
|
||||
}
|
||||
|
||||
func (account *Account) ResetPassword() error {
|
||||
var passwordReset uuid.UUID
|
||||
if err := passwordReset.Generate(uuid.V4); err != nil {
|
||||
return fmt.Errorf("failed to generate password reset uuid: %w", err)
|
||||
}
|
||||
account.Salt = nil
|
||||
account.PasswordHash = nil
|
||||
account.PasswordReset = &passwordReset
|
||||
return nil
|
||||
}
|
||||
|
||||
func (account *Account) SetPassword(password string) {
|
||||
account.Salt = helpers.GenerateSalt()
|
||||
account.PasswordHash = helpers.HashPassword(password, account.Salt)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue