Files
crockery/internal/store/account.go

31 lines
867 B
Go
Raw Normal View History

package store
import (
"golang.org/x/crypto/bcrypt"
)
// HashPassword turns a plaintext password into a crypt()ed string, using bcrypt
func HashPassword(password string) (string, error) {
b, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
return string(b), err
}
func CheckPassword(hashed, plain string) bool {
return bcrypt.CompareHashAndPassword([]byte(hashed), []byte(plain)) == nil
}
// Account is stored in the database as domains/<domain>/accounts/<id>/config
type Account struct {
// The username is typically user@example.com - the user is required to
// enter it *exactly* to log in.
Username string `storm:"id"`
// Whether the user is an admin or not. Typically, only postmaster@example.com
// is an admin, but others may be set up too if desired.
Admin bool
// As generated by HashPassword
PasswordHash string
}