'Wordpress Update User's Password with PHP

I have a webapp that uses Wordpress for it's authentication. I have an Account options page there. When opened, it contains a password update section. I POST this to my PHP script and run this code:

wp_update_user(array('ID' => getUserIDWP(), 'user_pass' => $_POST['newpass']))

It logs me out of my current Wordpress session, but when I try to log back in with the password I specified there, it says that I entered an incorrect password. I'd appreciate if someone could shed some light on this subject.

Note: the getUserIDWP() function is an alias for $current_user->ID; and the other related stuff.



Solution 1:[1]

Try below code, it won't log you out after password change and it works with Ajax too. Also, no need to reset cookies/session after it.

$userdata['ID'] = 1; //user ID
$userdata['user_pass'] = 'new_password';
wp_update_user( $userdata ); // this will handle encryption and everything

Cheers

Solution 2:[2]

I know it's late but...

I had a similar problem and it turns out there was an entry in the usermeta table called user_pass. I deleted that entry and I could log in again.

Maybe this will help somebody - I spent the last hour trying to figure out what I did wrong.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 NickOpris