我仍然是wordpress的新手,我只是在尝试检查密码(我确定我在某处错过了一些东西,但我感到迷失并且无法集中注意力):
$user = $_POST['user_name'];
$pass = $_POST['user_password'];
$wp_hasher = new PasswordHash(8, TRUE);
$result=$wpdb->get_results("SELECT * FROM Materials WHERE mtrname= '$user' ");
if($result){
$pwd=$wpdb->get_results("SELECT password FROM Materials WHERE mtrname= '$user' ");
if($wp_hasher->CheckPassword($pass, $pwd)) {
echo "YES, Matched";
} else {
echo "No, Wrong Password";
}
}
它总是显示
否,密码错误
警告:substr()期望参数1为字符串,数组为 /var/www/html/wp-includes/class-phpass.php,第124行
我知道CheckPassword函数必须仅接收String,并且我正在提供Array,请提供任何帮助?
答案 0 :(得分:2)
$pwd
是一个数组,应该是一个字符串。
将get_results更改为get_row
和
$pwd=$wpdb->get_results("SELECT password FROM Materials WHERE mtrname= '$user' ");
成为
$pwdQuery=$wpdb->get_row("SELECT password FROM Materials WHERE mtrname= '$user' ");
$pwd = $pwdQuery->password;
答案 1 :(得分:1)
如果要检查特定用户的密码,则可以使用Wordpress默认功能进行检查
请检查下面的代码
$email = $_POST['email'];
$password = $_POST['password'];
//Here i retrieve the user information through email you can also retrieve user information through **username**
$user = get_user_by('email', $email);
$ID = $user->ID;
$user_login = $user->data->user_login;
$user_pass = $user->data->user_pass;
if(!wp_check_password($password, $user_pass, $ID)){
//bad password
}else{
//Correct information
}