Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can decode the password using BCryptPasswordEncoder?

I want to decode the encrypted value from database. I want to sent the actual password to user via mail when he gave forgot password.

The following is the code used for encoding the passowrd

BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
String password = passwordEncoder.encode(user.getPassword());

How can do the decode?

like image 612
Rajaa Avatar asked Jan 28 '23 18:01

Rajaa


2 Answers

BCrypt is a password hashing function, i.e. a one-way function.

You can't decrypt a BCrypt hash just like you can't go back from chicken mcnuggets to the original chicken.

You can only verify that two BCrypt hashes are the same, thus verifying that a supplied password matches the original one.

A typical solution to this is to send a single-use password reset link to the user, use secret questions or some other information confirming user identity to let them set a new password.

like image 81
rustyx Avatar answered Feb 02 '23 11:02

rustyx


It is not advisable to send the actual password to the user. you can send an activation link rather in an email.

like image 41
faridibin Avatar answered Feb 02 '23 11:02

faridibin