如何在更新Wordpress中的新密码之前验证数据库中的旧密码。 POST变量从更新密码页面窗口中提供以下数据。
Array
(
[old_password] => oldpass
[new_password] => newpass
[confirm_password] => newpass
)
是否有任何默认功能可以处理此密码更新问题。 wordpress加密密码后的加密方法是什么?
我仍然是wordpress的新手,在搜索此要求后找不到任何解决方法。请指导我解决。
答案 0 :(得分:2)
我有类似的问题,我已经解决了,这是您可以遵循的解决方案,它运作良好,我已经将它用于我自己的项目。如果你坚持下去,请告诉我。
if( $_POST['submitpassword'] )
{
$passdata = $_POST;
unset($_POST,$passdata['submitpassword']);
$user = wp_get_current_user(); //trace($user);
$x = wp_check_password( $passdata['old_password'], $user->user_pass, $user->data->ID );
if($x)
{
if( !empty($passdata['new_password']) && !empty($passdata['confirm_password']))
{
if($passdata['new_password'] == $passdata['confirm_password'])
{
$udata['ID'] = $user->data->ID;
$udata['user_pass'] = $passdata['new_password'];
$uid = wp_update_user( $udata );
if($uid)
{
$passupdatemsg = "The password has been updated successfully";
$passupdatetype = 'successed';
unset($passdata);
} else {
$passupdatemsg = "Sorry! Failed to update your account details.";
$passupdatetype = 'errored';
}
}
else
{
$passupdatemsg = "Confirm password doesn't match with new password";
$passupdatetype = 'errored';
}
}
else
{
$passupdatemsg = "Please enter new password and confirm password";
$passupdatetype = 'errored';
}
}
else
{
$passupdatemsg = "Old Password doesn't match the existing password";
$passupdatetype = 'errored';
}
}
答案 1 :(得分:0)
测试和工作代码
global $current_user;
get_currentuserinfo();
$username = $current_user->user_nicename;
$username = $username;
$oldpass = $_POST['cpassword'];
$user = get_user_by( 'login', $username );
if ( $user && wp_check_password( $oldpass, $user->data->user_pass, $user->ID) )
echo "That's it";
else
echo "Nope";