Check WordPress hashed password with plain password

12,621

Solution 1

you have passed wrong hash value , hash value for 965521425 is $P$BmI5G.LOoEx1iH.naNqVhWnSh5sMp31 and you just need to write below code into your file:

require_once($_SERVER['DOCUMENT_ROOT']."/wp-load.php");
 $password = '965521425';
 $hash = '$P$BmI5G.LOoEx1iH.naNqVhWnSh5sMp31';
 var_dump(wp_check_password($password, $hash));

exit;

Solution 2

In your code, you include the wp library and it looks like you redefine a function named wp_check_password but you do not call any function at all. Add the following line before the closing php tag ("?>") and try again.

echo (wp_check_password($password, $hash) ? 'TRUE' : 'FALSE');

Keep an eye on the error logs in case you miss some dependencies.

Solution 3

i would simply do this <?php wp_check_password( $password, $hash, $user_id ) ?> Refer

Share:
12,621

Related videos on Youtube

ManojGeek
Author by

ManojGeek

Updated on May 25, 2022

Comments

  • ManojGeek
    ManojGeek almost 2 years

    I am building a external application for which user login credentials will be taken from WordPress site database table 'users'

    WordPress uses PHPass hashing , I am unable to validate username and password for my external application as the password in database table 'users' is hashed

    I am trying to check plain password with hashed password using wp_check_password function but I am failing, nothing is written back with this code

    <?php
    
    $password = '965521425';
    $hash = '$P$9jWFhEPMfI.KPByiNO9IyUzSTG7EZK0';
    
    require_once('/home/nhtsoft/public_html/project/wp-includes/class-phpass.php');
    
    function wp_check_password($password, $hash) {
        global $wp_hasher;
    
        if ( empty($wp_hasher) ) {
            $wp_hasher = new PasswordHash(8, true);
        }
        $check = $wp_hasher->CheckPassword($password, $hash);
        return apply_filters('check_password', $check, $password, $hash);
    }    
    ?>
    

    this code is giving me an empty page.

    How to check this password so that I can use these WordPress credentials for external app login?

    • ManojGeek
      ManojGeek over 10 years
      wordpress will not use only md5 hashing. . . . @user2092317
  • ManojGeek
    ManojGeek over 10 years
    i have already tried this. . . and here nothing to do with $user_id
  • Bhumi Shah
    Bhumi Shah over 10 years
    yeah,i got output , you can place code into functions.php and var_dump(wp_check_password($password, $hash); exit; and check it.
  • ManojGeek
    ManojGeek over 10 years
    as i need this to be implemented in external application not releated to wordpress, i have included class-phpass.php file and wrote the above code. . . sorry but i didnt get you, where to place the code. . .can u please tell me in detail. . .
  • Bhumi Shah
    Bhumi Shah over 10 years
    if you are using external file, you need to load wp-load.php file. see code i have edited above.
  • ManojGeek
    ManojGeek over 10 years
    Superb. . .Thankyou so much @Bhumi