sandip
sandip

Reputation: 55

How to decrypt the hashed password in php ? password hashed with password_hash() method

I want to decrypt the encrypted password that is encrypted by php's password_hash() method.

<?php

    $password = 12345;
    $hashed_password = password_hash($password, PASSWORD_DEFAULT);

?>

in above code i want to decrypt $hashed_password to 12345. how can i do it.

Upvotes: 2

Views: 13865

Answers (2)

TsV
TsV

Reputation: 639

You don't need to

The used algorithm, cost and salt are returned as part of the hash. Therefore, all information that's needed to verify the hash is included in it. This allows the password_verify() function to verify the hash without needing separate storage for the salt or algorithm information.

    $passwordEnteredFirstTime = '12345';
    $passwordEnteredSecondTime = '12345';

    $passwordHash = password_hash($passwordEnteredFirstTime, PASSWORD_BCRYPT);
    $passIsValid = password_verify($passwordEnteredSecondTime, $passwordHash);
    echo $passIsValid ? 'correct password' : 'wrong password';

Upvotes: 5

fabrik
fabrik

Reputation: 14365

You can't.

password_hash() creates a new password hash using a strong one-way hashing algorithm.

From password_hash.

Upvotes: 3

Related Questions