-->

How to decrypt the hashed password in php ? passwo

2020-04-18 06:49发布

问题:

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.

回答1:

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';


回答2:

You can't.

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

From password_hash.