我在Laravel 5.1中使用内置的注册和登录代码
我在做什么?
我完成了注册并且凭据已成功保存。
问题是什么?
当我尝试登录时,它会显示"这些凭据与我们的记录不符。"
在 postLogin
方法中,我看到了代码:$credentials = $this->getCredentials($request);
,当我在$credentials
中打印值并发现Password
值为纯文本。
可能是因为执行下面的行始终显示用户未找到
if (Auth::attempt($credentials, $request->has('remember'))) {
请建议我的路径
答案 0 :(得分:0)
您应该使用bcrypt
来加密用户密码。
$user = new App\User;
$user->email = 'test@test.com';
$user->password = bcrypt('plain-text-password');
$user->save();
Hash :: check方法允许您验证给定的纯文本 string对应于给定的哈希值。
if (Hash::check('plain-text-password', $hashedPassword)) {
// The passwords match...
}
答案 1 :(得分:0)
我在框架中做了很多改变。这些更改就像在用户表中添加新列和代码更改一样。也从password
更改为Password
。然后我意识到在Authenticatable class
下getAuthPassword
函数,它必须是Password
而不是password