我正在尝试为一个学校项目开发一个登录系统,但我遇到了这个错误,我不知道如何修复它。
在我的数据库上,我将密码spy123
存储在 sha256 哈希中,但是当我尝试在 php 中获取它时,我什么也得不到。
当前代码:
// checks if the user/password combination works.
// $username | String - the username of the user to login
// $password | 32byteHash - the hashed password of the user
// return | Boolean - Returns true if the password works for that user.
function forumLib_checkLogin($username, $password){
$goodLogin = false; //Assume the password is wrong.
$obtainUserPassword_query = "SELECT password FROM forum_users WHERE username = '$username'";
$dbc = forumLib_connectToDB();
$results = mysqli_query($dbc, $obtainUserPassword_query);
forumLib_closeConnectionToDB($dbc);
echo "query: $obtainUserPassword_query <br />";
echo "results: ".mysqli_fetch_array($results)."<br />";
$row = mysqli_fetch_array($results);
echo "row[0]: ".$row[0]."<br />";
echo "password: $password <br />";
echo "DBpassword: $passwordOnDB <br />";
//if user exists
if($results != false){
//get password from DB
$row = mysqli_fetch_array($results);
$passwordOnDB = $row['password'];
//check password
if($password == $passwordOnDB){
//successfull login
$goodLogin = false;
}
}
return $goodLogin;
}
输出:
change password request detected
query: SELECT password FROM forum_users WHERE username = 'SpyMaster356'
results: Array
row[0]:
password: 7d9519224964c72a90b342c565fab1e4582d0e974043798f940b471304db0e24
DBpassword:
Current password does not match records.
sql查询没有错,因为我7d9519224964c72a90b342c565fab1e4582d0e974043798f940b471304db0e24
在手动输入时返回。
这真的让我很困惑。