27 lines
538 B
Go
27 lines
538 B
Go
package model
|
|
|
|
import (
|
|
"crypto/subtle"
|
|
"encoding/json"
|
|
"time"
|
|
|
|
"git.adyxax.org/adyxax/tfstated/pkg/helpers"
|
|
)
|
|
|
|
type AccountContextKey struct{}
|
|
|
|
type Account struct {
|
|
Id int
|
|
Username string
|
|
Salt []byte
|
|
PasswordHash []byte
|
|
IsAdmin bool
|
|
Created time.Time
|
|
LastLogin time.Time
|
|
Settings json.RawMessage
|
|
}
|
|
|
|
func (account *Account) CheckPassword(password string) bool {
|
|
hash := helpers.HashPassword(password, account.Salt)
|
|
return subtle.ConstantTimeCompare(hash, account.PasswordHash) == 1
|
|
}
|