我的password_verify()函数遇到问题
在我的Login.class.php文件中,我试图将用户输入的密码与数据库中的哈希密码进行比较,但这给了我很多麻烦
class Login extends Register{
private $data;
private $error;
public function __construct($post_data) {
$this->data = $post_data;
}
public function add(){
$pdoStatement = $this->connection()->prepare("SELECT * FROM user WHERE username = :username AND password = :password");
$pdoStatement->bindParam(':username', $_POST['username'], PDO::PARAM_STR);
$pdoStatement->bindParam(':password', $_POST['password'], PDO::PARAM_STR);
$pdoStatement->execute();
$result = $pdoStatement->fetch(PDO::FETCH_ASSOC);
if (!$result) {
return $this->error = '<div class="alert alert-danger" role="alert">Incorrect username or password</div>';
} else {
if(password_verify($_POST['password'], $result['password'])){
$_SESSION['username'] = $_POST['username'];
header('Location: index.php?login=success');
exit();
} else {
echo "Oups didn't work";
}
}
}
public function getError(){
return $this->error;
}
}
我尝试了很多事情,但是没有用:(我必须输入哈希密码才能登录
你能看到什么问题吗?
谢谢!
编辑:已解决!你们要说谢谢,我必须删除查询中的“ AND password =:password”!