blob: d47668abf9f6b84124e4fe0b752219f659d56ab8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
package model
import (
"crypto/subtle"
"encoding/json"
"time"
"git.adyxax.org/adyxax/tfstated/pkg/helpers"
)
type AccountContextKey struct{}
type Account struct {
Id string
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
}
|