【问题标题】:CakePHP bcrypt not workingCakePHP bcrypt 不工作
【发布时间】:2014-02-24 22:57:48
【问题描述】:

每次打电话

$bph = new BlowfishPasswordHasher();
return $bph->hash("test");

它给了我一个不同的字符串。怎么了?

编辑:

还有

return Security::hash("test", "blowfish);

剧照每次都给我不同的字符串

Configure::write('Security.salt', 'VFxyv9RHDvtc4WUOxNTx54V1qikWpy2eZ15iFKlb');

【问题讨论】:

  • 您的盐可能每次都会重新生成,这会产生不同的哈希值。你能提供自己的盐吗?
  • 什么盐?我是core.php中的那个?

标签: cakephp cakephp-2.4


【解决方案1】:

请通过这个:

根据定义,安全哈希是

Security::hash($string, $type = NULL, $salt = false);

Blowfish 比 bcrypt 更安全。

但是河豚的使用与其他算法略有不同。

如 md5、sha1 等

每次传递一个字符串($string) 都会返回相同的结果。

但是河豚每次都会产生新的结果。

在比较使用 bcrypt 散列的值时,应提供原始散列作为 $salt 参数。

示例:

创作用途:

$string = 'CakePhp';
// Create a hash using bcrypt
Security::setHash('blowfish');
$hash = Security::hash($string); // $hash is your blowfish hashed string

比较:

$newHash = Security::hash($string, 'blowfish', $hash);
If($hash == $newHash){
   echo "Matching.....";
}   

谢谢...

【讨论】:

  • 我明白了。这是否意味着我无法使用 Auth 组件登录?因为整个问题是 AuthComponent::login() 不起作用
  • 你应该问一个关于@ChristopherFrancisco 的单独问题(不,这并不意味着)。根据设计,河豚会为相同的输入提供不同的结果 - 您试图将其视为简单的哈希,但这不是它的工作方式see the docs
猜你喜欢
  • 2017-08-09
  • 1970-01-01
  • 2012-05-06
  • 2019-09-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多