tfstated/pkg/model/account.go
Julien Dessaux 922112e181
All checks were successful
main / main (push) Successful in 1m49s
main / deploy (push) Has been skipped
main / publish (push) Has been skipped
feat(webui): add password reset page
#20
2025-04-20 21:51:23 +02:00

35 lines
793 B
Go

package model
import (
"crypto/subtle"
"encoding/json"
"time"
"git.adyxax.org/adyxax/tfstated/pkg/helpers"
"go.n16f.net/uuid"
)
type AccountContextKey struct{}
type Account struct {
Id uuid.UUID
Username string
Salt []byte
PasswordHash []byte
IsAdmin bool
Created time.Time
LastLogin time.Time
Settings json.RawMessage
PasswordReset *uuid.UUID
}
func (account *Account) CheckPassword(password string) bool {
hash := helpers.HashPassword(password, account.Salt)
return subtle.ConstantTimeCompare(hash, account.PasswordHash) == 1
}
func (account *Account) SetPassword(password string) {
account.Salt = helpers.GenerateSalt()
account.PasswordHash = helpers.HashPassword(password, account.Salt)
account.PasswordReset = nil
}