【发布时间】:2011-01-15 04:43:10
【问题描述】:
这是来自PHP manual page for crypt()的示例:
<?php
$password = crypt('mypassword'); // let the salt be automatically generated
/* You should pass the entire results of crypt() as the salt for comparing a
password, to avoid problems when different hashing algorithms are used. (As
it says above, standard DES-based password hashing uses a 2-character salt,
but MD5-based hashing uses 12.) */
if (crypt($user_input, $password) == $password) {
echo "Password verified!";
}
?>
为什么会这样?我认为'mypassword' 是我希望实际管理员使用的密码。所以我先将其加密,并将其设置为等于$password。显然,我必须将其存储在数据库中。但在接下来的几行中,它被用作盐和我正在比较的东西,我不明白crypt($user_input, $password) 怎么可能等于$password,如果在后一种情况下我最好有正确的密码与$user_input 相同,但与$password 相比,与$password 进行了比较。如果最后一行是
if (crypt($user_input) == $password) {
echo "Password verified!";
}
我不明白什么?
【问题讨论】:
-
您应该使用更高级的技术,例如 md5、sha1 等。
-
哈哈。哈哈。哈哈。哈哈。如果你能和我一起踏上这段史诗般的旅程,我的朋友。 stackoverflow.com/questions/2235158/…