init
This commit is contained in:
commit
2586161abd
49 changed files with 4171 additions and 0 deletions
27
internal/database/account.go
Normal file
27
internal/database/account.go
Normal file
|
@ -0,0 +1,27 @@
|
|||
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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue