How to buy password typed with password encrypted in Wordpress

0

I'm developing a WordPress system and I need to check the current user's password on the password edit screen, however I'm having problems with the encryption used in wordpress. I tried the code below published in the codex itself, but I did not have success.

<?php
$wp_hasher = new PasswordHash(8, TRUE);

$password_hashed = '$P$B55D6LjfHDkINU5wF.v2BuuzO0/XPk/';
$plain_password = 'test';

if($wp_hasher->CheckPassword($plain_password, $password_hashed)) {
    echo "YES, Matched";
} else {
    echo "No, Wrong Password";
}
?>

link

Any tips?

    
asked by anonymous 16.03.2016 / 22:18

1 answer

1

Very easy to solve this problem, there is a function in wordpress that facilitates a lot, it goes down:

wp_check_password( $password, $hash, $user_id);

$ password, you receive the decrypted password. $ hash, receives the encrypted password. $ user_id, does not get the wordpress function to get the user id.

Example:

<?php
global $wpdb;
$user_ID = get_current_user_id();
// Pega do banco a senha criptografada
$result = $wpdb->get_results( "SELECT * FROM  wp_users WHERE id=$user_ID" );
foreach ( $result as $page )
{
   // Variável com a hash
   $senhahash = $page->user_pass.'<br/>';

}
$senhadigitada = "suasenha";
$result = wp_check_password($senhadigitada, $senhahash, $user_ID);
if ($result==1){
    echo "sua senha esta correta";
}else{
    echo "Sua Senha esta Incorreta";
}
?>
    
17.03.2016 / 17:54