【发布时间】:2013-07-29 21:55:38
【问题描述】:
我需要在 php.ini 中检查密码的有效性。密码在 django 中使用 pbkdf2 散列器进行散列,散列算法为 sha256。
https://gist.github.com/staydecent/1019680
Verifying Django Password in Ruby on Rails gives non-matching password
据我了解,存储 django 密码时,哈希样式是第一个组件,其次是复制次数,然后是盐,然后是哈希。
我已经成功提取了每个组件,但是下面的php不起作用。它返回一个正确长度的字符串,但不是正确的内容。我担心哈希码不起作用。我使用的哈希器来自这个网站: https://defuse.ca/php-pbkdf2.htm
这是我的 php:
//$enc_password is the password from database
$pieces = explode('$', $enc_password);
$iterations = $pieces[1];
$salt = $pieces[2];
$hash = $pieces[3];
//raw_password is user's entered password
if ($hash == base64_encode(pbkdf2("sha256", $raw_password, $salt, $iterations, 32, true)))
{
echo ("SUCCESS");
}
else
{
echo ("FAILED");
}
感谢任何和所有帮助!
【问题讨论】:
-
附注 - stackoverflow.com/questions/14047979/… 仅在 django/python 中编写一小部分并将成功或失败的 JSON 编码消息返回给 php 会有多糟糕?
标签: php django hash passwords encode