mercury/internal/database/account.go

28 lines
627 B
Go
Raw Normal View History

2023-09-03 00:23:48 +02:00
package database
import (
"emperror.dev/errors"
"github.com/oklog/ulid/v2"
"golang.org/x/crypto/bcrypt"
)
// Account is a single account. It can own many Blogs.
type Account struct {
ID ulid.ULID
Username string
Domain *string
Email *string
Password *[]byte
}
const ErrNoPassword = errors.Sentinel("user is a remote user and has no password")
// PasswordValid returns true if the given password is valid.
func (a Account) PasswordValid(input string) (bool, error) {
if a.Password == nil {
return false, ErrNoPassword
}
return bcrypt.CompareHashAndPassword(*a.Password, []byte(input)) == nil, nil
}