added record.PasswordHash() getter

This commit is contained in:
Gani Georgiev
2022-11-06 11:04:04 +02:00
parent 65693d1916
commit 46dc6cc47c
2 changed files with 21 additions and 4 deletions

View File

@@ -586,6 +586,11 @@ func (m *Record) SetLastVerificationSentAt(dateTime types.DateTime) error {
return nil
}
// PasswordHash returns the "passwordHash" auth record data value.
func (m *Record) PasswordHash() string {
return m.GetString(schema.FieldNamePasswordHash)
}
// ValidatePassword validates a plain password against the auth record password.
//
// Returns false if the password is incorrect or record is not from an auth collection.
@@ -594,10 +599,8 @@ func (m *Record) ValidatePassword(password string) bool {
return false
}
err := bcrypt.CompareHashAndPassword(
[]byte(m.GetString(schema.FieldNamePasswordHash)),
[]byte(password),
)
err := bcrypt.CompareHashAndPassword([]byte(m.PasswordHash()), []byte(password))
return err == nil
}