我正在使用 Andrew Moore 先生的方法(如何在 PHP 中使用 bcrypt 进行密码哈希?)来哈希用户密码。我做的是我有一个注册页面,它使用
$bcrypt = new Bcrypt(12);
$pass = $_POST['password']; //register password field
$hash= $bcrypt->hash($pass);
// then inserts $hash into database with users registered email (I've checked my mysql database and it indeed has an hashed item
接下来是一个登录页面,包括电子邮件和密码字段。我的想法是我的数据库中的电子邮件地址是唯一的。因此,在这种情况下,我编写了一个脚本,首先检查用户的电子邮件地址,然后如果存在,则验证与此相关的哈希密码。
$bcrypt = new Bcrypt(12);
$email = $_POST['email']; //from login email field
$pass_l = $_POST['password']; // from login password field
$hash_1= $bcrypt->hash($pass_1);
$chk_email= $dbh->prepare("SELECT password FROM table WHERE email = ?");
$chk_email -> execute(array($email));
while($row = $chk_email->fetch(PDO::FETCH_ASSOC)){
$chk_pass = $row['password']; //inside a while loop to get the password
$pass_isGood = $bcrypt->verify($hash_1, $chk_pass);
var_dump($pass_isGood); // I'm getting false
}
我不确定我做错了什么,我应该得到true。而且我已经将我的表字段设置为text
或者varchar(256)