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

11,237

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

Solution 2

You can't.

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

From password_hash.

Share:
11,237

Related videos on Youtube

sandip
Author by

sandip

Updated on June 04, 2022

Comments

  • sandip
    sandip almost 2 years

    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.

    • Dirk Scholten
      Dirk Scholten over 5 years
      You can't. That's the whole point of encrypting passwords.
    • Bruno Pessanha
      Bruno Pessanha over 5 years
      You are mixing encryption with hashing. The hash function is one way. You cannot decrypt it, unless a weak hash function was used, then you might find a collision.