我有具有自定义登录名的Laravel 5.7项目。在重定向页面等待2到3分钟等之后,如何让Laravel接受三次登录尝试?
public function loginPost(LoginRequest $request)
{
if (Auth::attempt(array('user_name' => $request->user_name, 'password' => $request->user_pass)))
{
if(Auth::check())
return redirect('/');
else
return back();
}
else
{
return "login faled call administrator";
}
}
您可以通过两种方式来做
例如,在throttle middleware
的路线中添加laravel bulit
Route::post("/user/login","LoginController@login")->middleware("throttle:10,2");
它将每2分钟发送10个请求
2。使用内置在Trait ThrottlesLogins
中
首先在loginController中添加ThrottlesLogins trait
,然后在登录方法中添加此行
if ($this->hasTooManyLoginAttempts($request)) {
$this->fireLockoutEvent($request);
return $this->sendLockoutResponse($request);
}
if(attempt()) {
$this->clearLoginAttempts($request);
}else {
$this->incrementLoginAttempts($request);
}
如果尝试成功,则在尝试方法中添加此行
$this->clearLoginAttempts($request);
否则失败登录,然后添加此其他条件下的行
$this->incrementLoginAttempts($request);