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

痞子三分冷 提交于 2019-12-02 09:08:08

问题


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.



来源:https://stackoverflow.com/questions/52273284/how-to-decrypt-the-hashed-password-in-php-password-hashed-with-password-hash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!