密码应该使用什么哈希函数?

  • 本文关键字:哈希 函数 密码 laravel
  • 更新时间 :
  • 英文 :


Laravel的默认UserFactory类包含以下定义方法:

public function definition()
{
return [
'name' => $this->faker->name(),
'email' => $this->faker->unique()->safeEmail(),
'email_verified_at' => now(),
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
'remember_token' => Str::random(10),
];
}

密码密钥包含散列密码字符串值。如果我想使用另一个密码值,我应该使用什么散列函数来像这样散列它:

'password' => HashFunctionName('mynewpassword');

?对于上下文:我使用Auth:attempt函数进行身份验证:

public function login(LoginRequest $request){
if (Auth::attempt($request->only('email', 'password'))){
$request->session()->regenerate();
return response('you are logged in');
}
return response('Credentials are not valid', 401);
}

默认情况下,Bcrypt将被用作哈希算法:

https://laravel.com/docs/8.x/hashing介绍代码使用IlluminateSupportFacadesHash::make($somePassword);,它将根据您在config/hashing.php中定义的设置为给定的密码创建一个Bcrypt散列。

最新更新