27 lines
627 B
Go
27 lines
627 B
Go
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
|
|
}
|