我有laravel 5.7项目 一切正常,但我有自定义登录
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";
}
}
如何让laravel在重定向页面等待2或3分钟后等3次接受登录尝试。
谢谢
答案 0 :(得分:3)
u可以通过两种方式完成
在SELECT Name
FROM Production.Product
WHERE
ProductID IN (SELECT ProductID FROM Production.ProductProductPhoto WHERE [Primary] = 1)
AND ProductID NOT IN (SELECT ProductID FROM Production.ProductProductPhoto WHERE [Primary] = 0);
的路线中添加laravel bulit
throttle middleware
每2分钟发送10个请求
2。使用内置的Route::post("/user/login","LoginController@login")->middleware("throttle:10,2");
首先在loginController中添加Trait ThrottlesLogins
,然后在登录方法中添加这一行
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);
答案 1 :(得分:3)
打开登录控制器
App\Http\Controllers\Auth\LoginController.php
并粘贴
protected $maxAttempts = 1;
protected $decayMinutes = 1;
答案 2 :(得分:0)
您需要在控制器中使用ThrottlesLogins
特性,然后可以通过属性maxAttempts
/ decayMinutes
....
class TagController extends Controller
{
use ThrottlesLogins;
protected $maxAttempts = 5;
protected $decayMinutes = 1;
...
答案 3 :(得分:0)
打开 App\Http\Controllers\Auth\AuthController.php 并添加以下几行:
protected $maxLoginAttempts = 10;
protected $lockoutTime = 120;