gpt4 book ai didi

php - (PHP) 如何将 crypt() 与 CRYPT_BLOWFISH 一起使用?

转载 作者:可可西里 更新时间:2023-10-31 23:00:09 24 4
gpt4 key购买 nike

首先,我发现要使用 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$')

然后其余的行就没问题了吗?

最佳答案

对于 5.3.0 之前的 PHP,crypt() 使用操作系统提供的库。如果您使用的是早期版本,那么您需要检查您的操作系统文档以查看它是否受支持(检查 CRYPT_BLOWFISH 常量的值)——如果不支持,则该算法在 PHP 的 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.

关于php - (PHP) 如何将 crypt() 与 CRYPT_BLOWFISH 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2235897/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com