2024-11-14 01:34:29 +01:00
|
|
|
package model
|
|
|
|
|
2024-11-16 00:36:17 +01:00
|
|
|
import (
|
|
|
|
"crypto/subtle"
|
|
|
|
"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 {
|
2024-11-16 00:36:17 +01:00
|
|
|
Id int
|
|
|
|
Username string
|
|
|
|
Salt []byte
|
|
|
|
PasswordHash []byte
|
|
|
|
IsAdmin bool
|
|
|
|
Created time.Time
|
|
|
|
LastLogin time.Time
|
|
|
|
Settings any
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|