dongtidai6519 2015-12-20 14:51
浏览 85
已采纳

检查散列/加密密码时的PHP登录问题

My checkPassword() method returns false every time even though I know it is right. I used the same method for hashing/salting as I did for checking and I made sure everything is the way it should be but it still returns false. I'm using 'Bcrypt-PHP-Class' found here to hash everything https://github.com/cosenary/Bcrypt-PHP-Class Here is how I hashed the password:

$password = Bcrypt::hashPassword($_POST['password']);

Here is how I check the password:

$check = Bcrypt::checkPassword($password, $user['password']);

($user is an array of the user's information like username,password,email etc.) $check is still false even after checking that everything is exactly right. There are no errors either. Thanks in advanced to anyone who can help me out. Bcrypt methods:

public static function checkPassword($password, $storedHash) {
if (version_compare(PHP_VERSION, '5.3') < 0) {
  throw new Exception('Bcrypt requires PHP 5.3 or above');
}

self::_validateIdentifier($storedHash);
$checkHash = crypt($password, $storedHash);

return ($checkHash === $storedHash);
}
public static function hashPassword($password, $workFactor = 0) {
if (version_compare(PHP_VERSION, '5.3') < 0) {
  throw new Exception('Bcrypt requires PHP 5.3 or above');
}

$salt = self::_genSalt($workFactor);
return crypt($password, $salt);
}
  • 写回答

1条回答 默认 最新

  • duanben1324 2015-12-20 15:07
    关注

    Why you don't use password_hash() ? (http://php.net/manual/fr/function.password-hash.php)

    And look into your DB if the password field is a varchar and minimum 60 characters (for password_hash, don't know for Bcrypt-PHP-class)

    EDIT : Bcrypt-PHP-Class create a 60 chars hash, check if your fields have this minimum

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么