First pass of authentication

This commit is contained in:
Leon Mika 2026-02-25 22:04:47 +11:00
parent c943864edc
commit 01c6e9de87
15 changed files with 311 additions and 42 deletions

View file

@ -1,6 +1,10 @@
package models
import "time"
import (
"time"
"golang.org/x/crypto/bcrypt"
)
type User struct {
ID int64
@ -9,6 +13,16 @@ type User struct {
TimeZone string
}
func (u *User) SetPassword(pwd string) {
bcrypted, _ := bcrypt.GenerateFromPassword([]byte(pwd), bcrypt.DefaultCost)
u.PasswordHashed = bcrypted
}
func (u User) CheckPassword(pwd string) bool {
err := bcrypt.CompareHashAndPassword(u.PasswordHashed, []byte(pwd))
return err == nil
}
func (u User) FormatTime(t time.Time) string {
if loc := getLocation(u.TimeZone); loc != nil {
return t.In(loc).Format("2006-01-02 15:04:05")