以下是 crypt() 函数的 PHP 手册页面中的示例:
为什么会这样工作? 我理解
我没有理解什么?
以下是来自PHP手册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!";
}
我没有理解什么?