bin/models/user.go

22 lines
413 B
Go
Raw Normal View History

2023-09-12 22:30:58 +02:00
package models
import (
"golang.org/x/crypto/bcrypt"
"gorm.io/gorm"
)
type User struct {
gorm.Model
DisplayName string
Email string `gorm:"unique"`
Salt string
HashedPassword []byte
}
func (u *User) MatchesPassword(password string) bool {
combined := append([]byte(u.Salt), []byte(password)...)
return bcrypt.CompareHashAndPassword(u.HashedPassword, []byte(combined)) == nil
}