我有一些关于auth尝试失败的帖子,但我的情况似乎有所不同.仍处于开发阶段,所以我的密码是纯文本.我尝试登录,但我一直变错,所以重定向回登录页面.
错误消息显示用户名/密码不匹配,但dd显示电子邮件和密码都正确.
什么可能导致这种失败?PS:这是我第一次使用laravel
web.php
Route::post('/login', 'AuthController@authenticate');
Route::get('/', 'PostController@index');
Run Code Online (Sandbox Code Playgroud)
AuthController
public function auth()
{
//dd($request);
// attempt to login the user
if (! auth()->attempt(request(['email', 'password']))) {
return back()->withErrors([
'message' => 'Username/Password does not macth'
]);
}
return redirect('/');
}
Run Code Online (Sandbox Code Playgroud)
PostController中
public function index()
{
$posts = Post::latest()->limit(3)->get();
return view('post.index', compact('posts'));
}
Run Code Online (Sandbox Code Playgroud)
在您的用户模型中使用此代码,只有在需要时才会自动对密码进行哈希处理:
public function setPasswordAttribute($value)
{
if( \Hash::needsRehash($value) ) {
$value = \Hash::make($value);
}
$this->attributes['password'] = $value;
}
Run Code Online (Sandbox Code Playgroud)
之后更改密码,因此您在数据库中拥有哈希密码
归档时间: |
|
查看次数: |
3556 次 |
最近记录: |