Home > AI > Backend > Wordpress >

how to validate password

Thank you very much for this intelligent guy!!

You can check this link on Stackoverflow

https://wordpress.stackexchange.com/questions/32004/how-to-validate-wordpress-generated-password-in-db-using-php

<?php
include_once($_SERVER['DOCUMENT_ROOT'].'/wp-includes/class-phpass.php' );

// prepare database connection
$ip_address="localhost";
$user_db="userdb";
$pass_db="passdb";

$conn= mysql_connect($ip_address,$user_db,$pass_db);
mysql_select_db("dbname",$conn);
if (!$conn){
            echo "Could not connect: " . mysql_error();
            exit();
}

// wordpress' username that his password going to compare
$user = 'test';
$user_name = htmlspecialchars($user,ENT_QUOTES);

// plain password to compare
$password = 'tespass';

$hasher = new PasswordHash(8, TRUE);

// get user_name's hashed password from wordpress database
$queryx = "select * from wa1gty5f_users where user_login='$user_name'";
$Resultx = mysql_query($queryx,$conn);

while($row = mysql_fetch_array($Resultx)){
     $passnya = $row[user_pass];
}

// compare plain password with hashed password
if ($hasher->CheckPassword( $password, $passnya )){
    echo "MATCHED";
} else {
    echo "NO MATCHED";
}
?>

Leave a Reply