让我给你看一下准确的代码:
$credentials = array(
'email' => $request->email,
'password' => hash('sha512', $request->password)
);现在返回true
User::where($credentials)->exists()但是,这将返回false
Auth::attempt($credentials)我正在使用sha512存储我的密码。为什么Auth::attempt返回false?
发布于 2022-02-02 19:16:17
Laravel Hash外观为存储用户密码提供了安全的Bcrypt和Argon2哈希。
但是,您可以像这样创建自定义哈希:
$user = User::where([
'email' => $request->email,
'password' => hash('sha512', $request->password)
])->first();
if($user){
Auth::login($user);
}Bcrypt是哈希密码的一个很好的选择,因为它的“工作因子”是可调的,这意味着生成哈希的时间可以随着硬件功率的增加而增加。当散列密码时,慢一点是好的。算法哈希密码的时间越长,恶意用户生成所有可能的字符串哈希值的“彩虹表”所花费的时间就越长,这些字符串哈希值可能用于对应用程序的强力攻击。
https://stackoverflow.com/questions/70960795
复制相似问题