【发布时间】:2011-10-09 20:23:15
【问题描述】:
我不理解php.net 的文档。在针对原始加密进行测试时,他们似乎使用加密版本的密码作为盐。
当我插入没有可选第二个参数(盐)的 crypt 时,我会得到相同密码的不同加密版本。这是预期的行为吗?
但是,如果我插入“d4”的第二个参数,那么对于相同的密码输入,我会得到相同的加密密码。预期行为。
在注册时插入之前:
$pass = crypt('$pass', 'd4'); // after this I insert $pass into the mysql table
登录测试:
$pass = crypt($pass, 'd4'); // after this I test $pass against the mysql table
PHP.net 文档:
<?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!";
}
?>
这是如何工作的?
【问题讨论】:
-
“看来他们正在使用加密版本的密码作为盐”你在哪里看到的?
-
代码贴在上面 - 当原始密码加密没有加盐时,他们为什么用密码加盐用户输入?
标签: php encryption