Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sam0081's avatar

how to decrypt bcrypt password

how to decrypt bcrypt password... i want to match old password..

0 likes
8 replies
MikeHopley's avatar

You can't. That's the point of using bcrypt to hash your users' passwords.

Why do you want to do this?

sam0081's avatar

@MikeHopley :- i encrypt password with bcrypt($password).. now there is hash password in database column..

i am requesting user to enter the old password for change the password.. i want to match the old password with the database password.. thats why.. any other solution

thanks

sam0081's avatar

@tykus :- i tried but bcrypt giving me something different for same thing..

MikeHopley's avatar
Level 17

Bcrypt will always output a different hash each time. That's normal.

Here's some code that checks whether the provided $suppliedPassword is correct. Put this in your controller:

use Auth;
use Hash;

private function passwordCorrect($suppliedPassword)
{
    return Hash::check($suppliedPassword, Auth::user()->password, []);
}
4 likes
martinbean's avatar

@sam0081 That’s to be expected: bcrypt generates different hashes for the same input.

You can check the old password against the hash in the database like this:

if (Hash::check($request->input('old_password'), $user->password)) {
    // The old password matches the hash in the database
}
2 likes

Please or to participate in this conversation.