1 回答

TA貢獻1998條經驗 獲得超6個贊
您正在使用 PDOStatement 對象執行提取,但不存儲該提取的結果。相反,您在 PDOStatement 對象本身中查找密碼。嘗試:
public function login ( $username, $password ) {
$u_login = $this->conn->prepare("SELECT * FROM korisnici WHERE username = :username");
$u_login->bindValue(':username', $username);
$u_login->execute();
/*
* Now that the prepared statement has been built and executed, we can
* try to fetch a matching user and store it as $user - this will be an
* array if successful or boolean false if not.
*/
$user = $u_login->fetch(PDO::FETCH_ASSOC);
/* Check that $user is not false and the password_verify returns boolean
* true when comparing the password to the hashed password stored in the
* database.
*/
if ($user && password_verify($password, $user['password'])) {
// User was found and password matched
}
}
- 1 回答
- 0 關注
- 136 瀏覽
添加回答
舉報