Checks (compares) the provided key for password recovery with the hash of that key in the database.
The key hash is created by the function get_password_reset_key() during the password recovery request and is stored in the database, in the table wp_users in the user_activation_key field.
The key stored in the database is valid for one day (24 hours) from the moment of its creation.
WP_User object if the specified key has passed the check (is equal to the hash).
WP_Error object if the key does not equal the hash or has expired.
Usage
check_password_reset_key( $key, $login );
$key(string) (required)
Key to compare with the hash. This key is usually sent via email as a link.
$login(string) (required)
The username of the user whose key hash needs to be retrieved from the database and compared with the value of $key.
Examples
0
#1 Example of creating and verifying a key to restore a pasword
// create a key for user 1 with the username siesta
$user = get_userdata( 1 );
$key = get_password_reset_key( $user ); // ZedUm9FEt48Kp4aGb5i8
// check the created key
$ok = check_password_reset_key( $key, 'siesta' );
if( is_wp_error( $ok ) ){
echo $ok->get_error_message();
}
else {
echo 'The key has been verified. You can send a new password to the email.';
}