Slight refactor to re-use Auth structures

* Now Auth.Login is a consolidated attempt to verify password, 2fa code
and verified status
This commit is contained in:
🐙PiperYxzzy
2022-04-30 16:03:42 +02:00
parent 47ac0cdc07
commit 4b270733a7
2 changed files with 51 additions and 17 deletions

View File

@@ -21,6 +21,22 @@ func (a *Auth) SetPassword(pass string) error {
return nil
}
func (a *Auth) Login(pass string, tfCode string) (error, bool) {
if err := a.CheckPassword(pass); err != nil {
return err, false
}
if err := a.ValidateTwoFactor(tfCode, time.Now()); err != nil {
return err, true
}
if !a.Verified {
return errors.New("not yet verified"), true
}
return nil, false
}
func (a *Auth) CheckPassword(pass string) error {
return bcrypt.CompareHashAndPassword([]byte(a.PasswordHash), []byte(pass))
}