java - How to get original password from BCryptPasswordEncoder -


i'm using spring security application. when user register first time, passwords encrypted bcryptpasswordencoder.

bcryptpasswordencoder passwordencoder = new bcryptpasswordencoder(); string hashedpassword = passwordencoder.encode(password); 

now, in case of password changing, users enter current password , need check if current password same against encrypted password saved in database.

i know not possible generate 2 same encrypted hash same string bcryptpasswordencoder. way compare passwords if same original password saved in database , compare current entered password.

so, there way compare passwords or original password database saved hashed password?

you need check raw password against encoded password in db. example,

bcryptpasswordencoder bcryptpasswordencoder = new bcryptpasswordencoder(); string p = bcryptpasswordencoder.encode("somecoolpassword"); system.out.println(bcryptpasswordencoder.matches("somecoolpassword", p)); 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -