我在 php 中使用 bcrypt/blowfish,当我将成本参数设置为 10 美元(我认为是 1024 轮)时,加密过程需要 0.1 秒。如果我将其设置为 12 美元,则需要 0.3 秒。我的问题是:这是否占用了 0.3 秒的 cpu 时间,即如果我有 100 个用户运行这个进程,他们都必须等待 30 秒(0.3 x 100)吗?(编辑:由于双核/多线程处理可能会更短,但即使是 10 秒也是不可接受的)。
另外:保留这个成本参数有什么好的价值?有些人推荐 16 美元,但在我的网站(由大型网络主机托管)上花费了 5 秒以上。
顺便说一句,我正在使用以下代码来检查它所花费的时间:
<?php
// set a password to work with
$var1 = "doodoo1234";
//echo that password onto the screen
echo $var1 . "<br /><br />";
//Start the clock
$time_start = microtime(true);
//Run blowfish function to encrypt the password
$hashedpass = PassHash::blowfishhash($var1);
//stop the clock
$time_end = microtime(true);
//echo the password to the screen
echo $echohashedpass . "<br /><br />";
//Echo the length of the encrypted password to the screen
//(this taught me that blowfish always returns a 60 varchar string)
echo strlen($sajpass). "<br /><br />";
$time = $time_end - $time_start;
echo "that took $time seconds\n";
?>