[JAVA] Password change function

Implementation of password change function in Spring Described as a record of learning

Matching the DB password with the entered password

・ Hashed password is registered



public Entity save(Entity user, String rawPassword){

    String encodedPassword = passwordEncoder.encode(password);
    return Repository.save(user);

What is Password Encoder?

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.


//Matching the entered password with the hashed password of the DB
if (passwordEncoder.matches(rawPass,dbPass)){
   //If they match, the screen transitions
   return "/index";

Image from Gyazo Spring Security Official Reference

Recommended Posts

Password change function
Login function
JavaScript function
SpringMVC-Interceptor function