Solución:
El problema se resuelve usando el siguiente código:
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
encoder.matches(password, user.getPassword());
password
– desde formulario (JSP)
user.getPassword()
– de la base de datos
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
if(email.equalsIgnoreCase(user.getEmail()) && encoder.matches(password, user.getPassword())) {
userService.deactivateUserByID(user.getId());
redirectAttributes.addFlashAttribute("successmsg", "Your account has been deactivated successfully.");
model.setViewName("redirect:/logout");
}else{
redirectAttributes.addFlashAttribute("errormsg", "Email or Password is incorrect");
model.setViewName("redirect:/app/profile/deactivate");
}
BCryptPasswordEncoder bcrypt = new BCryptPasswordEncoder();
boolean isPasswordMatches = bcrypt.matches(userenteredpasswordWithotEncryoted, encryptedPasswordFromDb);
Ejemplo:
boolean isPasswordMatches = bcrypt.matches(
"Truck123",
"$2a$10$kcVH3Uy86nJgQtYqAFffZORT9wbNMuNtqytcUZQRX51dx6IfSFEd."
);
if (isPasswordMatches) { // correct password
...
} else { // Wrong Password
...
}
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)