gpt4 book ai didi

php - 在自定义查询php中匹配用户密码

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:28:24 25 4
gpt4 key购买 nike

我想在我的自定义 php 应用程序中使用我的 WordPress 用户表。现在的问题是,如果我尝试根据 md5('password'); 检查密码 - 它没有用。我该如何解决这个问题。我的查询是

if($stmt = $mysqli -> prepare("
SELECT user_login, display_name
FROM wp_users
WHERE user_login=? AND user_pass=?
")){
/* Bind parameters
s - string, b - boolean, i - int, etc */
$stmt -> bind_param("ss", $username, md5($password));

如何将密码与 WordPress 加密密码相匹配?用 Wp 类更新。

function wp_hash_password($password) {
global $wp_hasher;

if ( empty($wp_hasher) ) {
require_once('class-phpass.php');
// By default, use the portable hash from phpass
$wp_hasher = new PasswordHash(8, true);
}

return $wp_hasher->HashPassword( trim( $password ) );
}


if(isset($_POST['login']))
{


$username = clean($_POST['login']['username']);
$password = wp_hash_password($_POST['login']['password']);
echo $password;
exit();
/* Create a new mysqli object with database connection parameters */
$mysqli = mysqli_connect('localhost', 'root', '', 'C347278_wordpress2');

if(mysqli_connect_errno())
{
echo "Connection Failed: " . mysqli_connect_errno();
exit();
}

if($stmt = $mysqli -> prepare("
SELECT user_login, display_name
FROM wp_users
WHERE user_login=? AND user_pass=?
")){
/* Bind parameters
s - string, b - boolean, i - int, etc */
$stmt -> bind_param("ss", $username, $password);

/* Execute it */
$result = $stmt -> execute();

//Check whether the query was successful or not
if ($result === false) {
die("Query failed");
}

/* Bind results to variables that will be used within the fetch() loop. */
$stmt -> bind_result($login_id, $display_name);

/* Check the number of rows returned. */
if ($stmt->num_rows != 1) {
//Login failed
$_SESSION['error_message'] = 'wrong User name OR Password';

}

/* Iterate over the results of the query. */
while ($stmt->fetch())
{
//Login Successful
session_regenerate_id();
/* We can use $login_id, $firstname and $lastname cause we binded the result to those variables above. */
$_SESSION['SESS_MEMBER_ID'] = $login_id;
$_SESSION['SESS_DISP_NAME'] = $display_name;
//$_SESSION['SESS_LAST_NAME'] = $lastname;
session_write_close();
header('Location:http://'.$_SERVER['SERVER_NAME'].'/app/'.$to);
exit();
}//main if close

/* Close statement */
$stmt -> close();
}

/* Close connection */
$mysqli -> close();
}

最佳答案

可以使用wordpress原生功能,

$hash = wp_hash_password( $password );

喜欢,

$stmt -> bind_param("ss", $username, wp_hash_password($password));

引用:http://codex.wordpress.org/Function_Reference/wp_hash_password

wp_hash_password() 位于 wp-includes/pluggable.php。

关于php - 在自定义查询php中匹配用户密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21375890/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com