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