I use Spring security in our Application and would like to validate user input with the password stored in the DB for the change password option.
The password is stored as follows in DB.
user.setPassword(new BCryptPasswordEncoder().encode("<userPassword>"));
Here the user entered password is encoded using the above logic and stored in the DB. Now I am just trying to get password from user for change password. After getting the password from user I encode using the above logic and try to compare with the DB. The encoded value seems to be different even I use the same logic for encoding.
My configuration from WebSecurityConfig
:
@Autowired
public void configAuthentication(final AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService).passwordEncoder(new BCryptPasswordEncoder());
}
I am not sure what is wrong with comparison.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…