Reorganize the store, add a FindAccounts method
This commit is contained in:
@@ -18,9 +18,7 @@ type Interface interface {
|
||||
SetDomain(string) error
|
||||
SetTLS([]byte, []byte) error
|
||||
|
||||
CreateAccount(*Account) error
|
||||
FindAccount(string) (*Account, error)
|
||||
FindAccountWithPassword(string, string) (*Account, error)
|
||||
AccountInterface
|
||||
|
||||
io.Closer
|
||||
}
|
||||
@@ -142,32 +140,6 @@ func (c *concrete) SetTLS(certPEM, keyPEM []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *concrete) CreateAccount(account *Account) error {
|
||||
return c.storm.Save(account)
|
||||
}
|
||||
|
||||
func (c *concrete) FindAccount(username string) (*Account, error) {
|
||||
var account Account
|
||||
|
||||
return &account, c.storm.One("Username", username, &account)
|
||||
}
|
||||
|
||||
func (c *concrete) FindAccountWithPassword(username, password string) (*Account, error) {
|
||||
account, err := c.FindAccount(username)
|
||||
|
||||
if err != nil {
|
||||
// Always do a bcrypt check to avoid timing attacks
|
||||
_ = CheckPassword("", "")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !CheckPassword(account.PasswordHash, password) {
|
||||
return nil, fmt.Errorf("bad password")
|
||||
}
|
||||
|
||||
return account, nil
|
||||
}
|
||||
|
||||
func (c *concrete) Close() error {
|
||||
return c.storm.Close()
|
||||
}
|
||||
|
Reference in New Issue
Block a user