summaryrefslogtreecommitdiff
path: root/pkg/model/account.go
blob: 7a69685d88b5cd320e4bd9d8653f2b59479b79af (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
package model

import (
	"crypto/subtle"
	"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     any
}

func (account *Account) CheckPassword(password string) bool {
	hash := helpers.HashPassword(password, account.Salt)
	return subtle.ConstantTimeCompare(hash, account.PasswordHash) == 1
}