Php Laravel使用多少成本/回合进行散列?
我试图了解以下函数是如何从BcryptHasher.php文件中的Laravel 4.2中工作的:Php Laravel使用多少成本/回合进行散列?,php,laravel,laravel-4,laravel-5,laravel-5.1,Php,Laravel,Laravel 4,Laravel 5,Laravel 5.1,我试图了解以下函数是如何从BcryptHasher.php文件中的Laravel 4.2中工作的: /** * Hash the given value. * * @param string $value * @param array $options * @return string * * @throws \RuntimeException */ public function make($va
/**
* Hash the given value.
*
* @param string $value
* @param array $options
* @return string
*
* @throws \RuntimeException
*/
public function make($value, array $options = [])
{
$cost = isset($options['rounds']) ? $options['rounds'] : $this->rounds;
$hash = password_hash($value, PASSWORD_BCRYPT, ['cost' => $cost]);
if ($hash === false) {
throw new RuntimeException('Bcrypt hashing not supported.');
}
return $hash;
}
我想除了这句话我什么都懂:
$cost = isset($options['rounds']) ? $options['rounds'] : $this->rounds;
我知道$this->rounds的默认值被设置为10,这就是密码散列的“成本”。但是,我不清楚$options数组在做什么,以及这会如何影响成本 调用
make
方法时,可以传入选项
例如,使用facade:
$hashed = Hash::make($value, ['rounds' => 8]);
如果您不传入
成本
,它将使用$this->rounds
,即10
如果设置了$options数组(由调用该方法的用户设置),则使用$options['rounds']获得的值作为$cost,而不是$this->rounds。对于Laravel 4.2,我不是100%确定,但是对于5.7,该选项不是成本
,但是轮数
。所以它看起来像是$hashed=Hash::make($value,['rounds'=>8])代码>