我一直在尝试为基于Android的应用程序创建登录/注册系统。我已经能够使注册系统正常工作,但是当前我的应用程序检查用户是否存在于数据库中,然后不管密码是否正确都将其登录。我之前曾与某人交谈过,他们说使用password_verify(如下所示)来解决问题。
password_verify($password, $response['password']);
但是,我目前正在努力实现代码并使代码正常工作。我只是想知道是否有人会帮助我阐明如何进行设置。任何帮助将不胜感激!
下面,我从我的login.php文件中添加了代码。
<?php
require("password.php");
$con = mysqli_connect("localhost", "xxxxxxxxx", "xxxxxxxxxxx", "xxxxxxxxx");
$username = $_POST["username"];
$password = $_POST["password"];
$passwordHash = password_hash($password, PASSWORD_DEFAULT);
$statement = mysqli_prepare($con, "SELECT * FROM user WHERE username = ? AND password = ?");
mysqli_stmt_bind_param($statement, "ss", $username, $passwordHash);
mysqli_stmt_execute($statement);
mysqli_stmt_store_result($statement);
mysqli_stmt_bind_result($statement, $UserID, $Name, $Username, $Email, $PasswordHash);
$response = array();
$response["success"] = false;
while(mysqli_stmt_fetch($statement)){
$response["success"] = true;
$response["name"] = $name;
$response["email"] = $email;
$response["username"] = $username;
$response["password"] = $password;
}
echo json_encode($response);
?>