I am try to check the Hashpasword with .equals() method but it is showing stored password and user entered password as false even though both are same please suggest me a code fix. HashedPassword is saving is working fine while registering.
//Java public boolean userAuthentication(Userdetails userdetails) { Optional salt = passwordUtils.generateSalt(CableTVConstants.SALT_LENGTH); Optional userinfo = userDetailService.findById(userdetails.getUsername()); if(userinfo.isPresent()) { return passwordUtils.verifypassword(userdetails.getPassword(),userinfo.get().getPassword(),salt.get()); } logger.log(Level.ALL,"Invalid user credentials"); return false; } public boolean verifypassword(String password, String key, String salt) { Optional password_check = generateHashPassword(password,salt); if(!password_check.isPresent()) { return false; } return password_check.get().equals(key); }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I am try to check the Hashpasword with .equals() method but it is showing stored password and user entered password as false even though both are same please suggest me a code fix. HashedPassword is saving is working fine while registering.
//Java
public boolean userAuthentication(Userdetails userdetails)
{
Optional salt = passwordUtils.generateSalt(CableTVConstants.SALT_LENGTH);
Optional userinfo = userDetailService.findById(userdetails.getUsername());
if(userinfo.isPresent())
{
return passwordUtils.verifypassword(userdetails.getPassword(),userinfo.get().getPassword(),salt.get());
}
logger.log(Level.ALL,"Invalid user credentials");
return false;
}
public boolean verifypassword(String password, String key, String salt)
{
Optional password_check = generateHashPassword(password,salt);
if(!password_check.isPresent())
{
return false;
}
return password_check.get().equals(key);
}