简体   繁体   English

Wordpress 更新用户密码 PHP

[英]Wordpress Update User's Password with PHP

I have a webapp that uses Wordpress for it's authentication.我有一个使用 Wordpress 进行身份验证的网络应用程序。 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:我将此发布到我的 PHP 脚本并运行此代码:

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.它将我从当前的 Wordpress session 中注销,但是当我尝试使用我在那里指定的密码重新登录时,它说我输入了错误的密码。 I'd appreciate if someone could shed some light on this subject.如果有人能阐明这个主题,我将不胜感激。

Note: the getUserIDWP() function is an alias for $current_user->ID;注意: getUserIDWP() function 是$current_user->ID; and the other related stuff.和其他相关的东西。

WordPress has provided a simple function in new release of WP as below. WordPress 在 WP 的新版本中提供了一个简单的功能,如下所示。

wp_set_password( $new_password, $user_id );

OR you can use below code, it will not logout user:或者您可以使用以下代码,它不会注销用户:

$userdata['ID'] = 1;
$userdata['user_pass'] = 'new_password';
wp_update_user( $userdata );

https://stackoverflow.com/a/35336444/4819200 https://stackoverflow.com/a/35336444/4819200

It worked for me to update 'user_pass' using both update_user_meta and wp_update_user :使用update_user_metawp_update_user更新'user_pass'对我wp_update_user

update_user_meta($user_id, 'user_pass', $newpassword);
wp_update_user( array ('ID' => $user_id, 'user_pass' => $newpassword) ) ;

try this one试试这个

    global $current_user;
    $password = 'Abc123456';
    wp_set_password($password, $current_user->ID);

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.我遇到了类似的问题,结果发现 usermeta 表中有一个名为 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.也许这会帮助某人 - 我花了最后一个小时试图找出我做错了什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM