use*_*840 4 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($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;
}
Run Code Online (Sandbox Code Playgroud)
我想我理解除了这一行之外的一切:
$cost = isset($options['rounds']) ? $options['rounds'] : $this->rounds;
Run Code Online (Sandbox Code Playgroud)
我知道$ this-> rounds的默认值设置为10,然后是密码将被散列的"成本".但是,我对$ options数组正在做什么以及如何影响成本感到困惑?
您可以在调用make方法时传入选项.
例如,使用立面:
$hashed = Hash::make($value, ['rounds' => 8]);
Run Code Online (Sandbox Code Playgroud)
如果你没有通过cost,它会使用$this->rounds,这是10.
| 归档时间: |
|
| 查看次数: |
2442 次 |
| 最近记录: |