Reorganize the store, add a FindAccounts method

This commit is contained in:
2018-03-08 00:46:22 +00:00
parent 442ca833ea
commit be7ca459a5
4 changed files with 53 additions and 40 deletions

View File

@@ -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()
}