Implementation of password change function in Spring Described as a record of learning
・ Hashed password is registered
Service.java
@Autowired
PasswordEncoder;
public Entity save(Entity user, String rawPassword){
String encodedPassword = passwordEncoder.encode(password);
user.setPassword(encodedPassword);
return Repository.save(user);
}
A class provided by Spring Security that is related to encryption when storing a login password in a DB etc. ・ Encrypt (hash) the password -Check if the password entered at the time of authentication matches the saved encrypted password. Spring Security Official Reference
-Check if the entered password matches the hashed password stored in the DB.
Controller.java
//Matching the entered password with the hashed password of the DB
if (passwordEncoder.matches(rawPass,dbPass)){
//If they match, the screen transitions
return "/index";
}