首先,我看到要使用CRYPT_BLOWFISH,我需要使用以$2a$开头的16个字符的盐。然而,php.net documentation for crypt()说有些系统不支持CRYPT_BLOWFISH。这种情况有多频繁?
接下来,从他们在文档上的示例中,我看到我使用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!";
}
?>为了使用CRYPT_BLOWFISH,我唯一需要修改的就是第一行,让它变成这样;
crypt('mypassword', '$2a$07$usesomesillystringforsalt$')然后剩下的行就没问题了吗?
发布于 2010-02-10 18:24:56
对于PHP 5.3.0之前的版本,crypt()使用操作系统提供的lib。如果你使用的是一个较早的版本,那么你需要检查你的操作系统文档,看看它是否被支持(检查CRYPT_BLOWFISH常量的值)-如果不是,那么算法是在mcrypt()扩展中实现的。
您从文档中引用的示例似乎没有多大意义:
$stored_password=fetch_password($user);
if (crypt($_REQUEST['password'],$stored_password)===$stored_password) {
// note that crypt automatically extracts the salt and alogrithm type
// from $stored_password
....您只需在创建密码时指定前缀($2a$)。
HTH
结果表明,C.
https://stackoverflow.com/questions/2235897
复制相似问题