chore(webui): finish implementing password reset
All checks were successful
main / main (push) Successful in 1m52s
main / deploy (push) Has been skipped
main / publish (push) Has been skipped

#20
This commit is contained in:
Julien Dessaux 2025-05-02 22:44:16 +02:00
parent 20bc9fe17a
commit 4f68621bad
Signed by: adyxax
GPG key ID: F92E51B86E07177E
9 changed files with 126 additions and 42 deletions

View file

@ -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)