verifying password

master
Niko Abeler 3 months ago
parent 7165e4c30a
commit 2acca40afe
  1. 7
      user.go
  2. 12
      user_test.go

@ -245,3 +245,10 @@ func (user User) ResetPassword(password string) error {
config.PassworHash = string(bytes)
return user.SetConfig(config)
}
func (user User) VerifyPassword(password string) bool {
err := bcrypt.CompareHashAndPassword(
[]byte(user.Config().PassworHash), []byte(password),
)
return err == nil
}

@ -302,3 +302,15 @@ func TestResetUserPassword(t *testing.T) {
assertions.Assert(t, user.Config().PassworHash != "", "Password Hash should not be empty")
assertions.Assert(t, user.Config().PassworHash != "test", "Password Hash should not be test")
}
func TestVerifyPassword(t *testing.T) {
user := getTestUser()
user.ResetPassword("test")
assertions.Assert(t, user.VerifyPassword("test"), "Password should be correct")
assertions.Assert(t, !user.VerifyPassword("test2"), "Password should be incorrect")
assertions.Assert(t, !user.VerifyPassword(""), "Password should be incorrect")
assertions.Assert(t, !user.VerifyPassword("Test"), "Password should be incorrect")
assertions.Assert(t, !user.VerifyPassword("TEST"), "Password should be incorrect")
assertions.Assert(t, !user.VerifyPassword("0000000"), "Password should be incorrect")
}

Loading…
Cancel
Save