Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel使用多少成本/回合进行散列?_Php_Laravel_Laravel 4_Laravel 5_Laravel 5.1 - Fatal编程技术网

Php Laravel使用多少成本/回合进行散列?

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

我试图了解以下函数是如何从BcryptHasher.php文件中的Laravel 4.2中工作的:

/**
     * 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])