pye/user.go

31 lines
607 B
Go
Raw Normal View History

2024-10-11 11:38:08 +03:00
package main
import (
"github.com/google/uuid"
"golang.org/x/crypto/bcrypt"
)
type User struct {
uuid uuid.UUID
email string
hash []byte // bcrypt hash of password
}
func (u User) PasswordFits(password string) bool {
err := bcrypt.CompareHashAndPassword(u.hash, []byte(password))
return err == nil
}
func NewUser(email, password string) (User, error) {
hash, err := bcrypt.GenerateFromPassword([]byte(password), 14)
if err != nil {
return User{}, err
}
return User{uuid.New(), email, hash}, nil
}
2024-10-11 23:57:57 +03:00
// TODO: Implement
func ByEmail(email string) (User, bool) {
return UserByEmail(email)
2024-10-11 11:38:08 +03:00
}