2024-11-14 01:34:29 +01:00
|
|
|
package model
|
|
|
|
|
2024-11-16 00:36:17 +01:00
|
|
|
import (
|
|
|
|
"crypto/subtle"
|
2025-01-30 00:19:16 +01:00
|
|
|
"encoding/json"
|
2024-11-16 00:36:17 +01:00
|
|
|
"time"
|
|
|
|
|
2024-11-17 00:05:22 +01:00
|
|
|
"git.adyxax.org/adyxax/tfstated/pkg/helpers"
|
2024-11-16 00:36:17 +01:00
|
|
|
)
|
2024-11-14 01:34:29 +01:00
|
|
|
|
2024-11-15 23:48:35 +01:00
|
|
|
type AccountContextKey struct{}
|
|
|
|
|
2024-11-14 01:34:29 +01:00
|
|
|
type Account struct {
|
2025-01-31 20:53:29 +01:00
|
|
|
Id string
|
2024-11-16 00:36:17 +01:00
|
|
|
Username string
|
|
|
|
Salt []byte
|
|
|
|
PasswordHash []byte
|
|
|
|
IsAdmin bool
|
|
|
|
Created time.Time
|
|
|
|
LastLogin time.Time
|
2025-01-30 00:19:16 +01:00
|
|
|
Settings json.RawMessage
|
2024-11-16 00:36:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (account *Account) CheckPassword(password string) bool {
|
2024-11-17 00:05:22 +01:00
|
|
|
hash := helpers.HashPassword(password, account.Salt)
|
2024-11-16 00:36:17 +01:00
|
|
|
return subtle.ConstantTimeCompare(hash, account.PasswordHash) == 1
|
|
|
|
}
|