我不理解php.net的文档。在测试原始加密时,他们似乎使用了密码的加密版本作为盐。
当我不带可选的第二个参数(the salt)插入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 tablePHP.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!";
}
?> 这是怎么回事?
发布于 2011-07-21 08:33:40
由于crypt()仅使用CRYPT_SALT_LENGTH参数的前两个字符(或其他任何参数),因此传入加密密码(其中第一个字符是最初用于加密密码的盐)是正确的。
如果没有传入任何salt参数,则会生成并使用随机的salt。
发布于 2011-07-21 08:41:34
如果你的问题是...对于某些加密密码,对于相同的密码/输入,返回不同的加密字符串是正常的吗?答案是肯定的。我不知道你说的盐是什么意思。加盐就是加盐。归根结底,它是一个烦人的东西,毫无意义。不建议使用口令或加密形式的口令作为salt,但通常使用短语的某些随机哈希(base64)。如果这不起作用,请告诉我,我会再试一次。
https://stackoverflow.com/questions/6770076
复制相似问题