Verification emails

This commit is contained in:
2024-03-21 21:10:56 +01:00
parent 782e762019
commit b9a1fcd02a
9 changed files with 292 additions and 79 deletions

View File

@ -7,7 +7,6 @@ func HashPassword(password string, cost int) (string, error) {
return string(bytes), err
}
func CheckPasswordHash(password, hash string) bool {
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
return err == nil
func CheckPasswordHash(password, hash string) error {
return bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
}

View File

@ -11,11 +11,11 @@ func TestHashValid(t *testing.T) {
password := "qwertyu9"
hpass, err := hash.HashPassword(password, 10)
assert.NoError(t, err)
assert.True(t, hash.CheckPasswordHash(password, hpass))
assert.NoError(t, hash.CheckPasswordHash(password, hpass))
}
func TestHashInvalid(t *testing.T) {
password := "qwertyu9"
invhash := "qwertyu9"
assert.False(t, hash.CheckPasswordHash(password, invhash))
assert.Error(t, hash.CheckPasswordHash(password, invhash))
}