tfstated/pkg/model/account.go
Julien Dessaux 2bf1731343
All checks were successful
main / main (push) Successful in 1m53s
main / deploy (push) Has been skipped
main / publish (push) Has been skipped
feat(webui): add user account status page
2025-04-13 09:33:11 +02:00

29 lines
598 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
}