Php 限制Laravel 5.7中的登录尝试

Php 限制Laravel 5.7中的登录尝试,php,laravel,laravel-5,laravel-5.7,Php,Laravel,Laravel 5,Laravel 5.7,我有一个自定义登录的Laravel 5.7项目。我怎样才能让Laravel在页面重定向后接受三次登录尝试,等待2或3分钟,等等 public function loginPost(LoginRequest $request) { if (Auth::attempt(array('user_name' => $request->user_name, 'password' => $request->user_pass))) { if(Auth:

我有一个自定义登录的Laravel 5.7项目。我怎样才能让Laravel在页面重定向后接受三次登录尝试,等待2或3分钟,等等

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 bulit

    Route::post("/user/login","LoginController@login")->middleware("throttle:10,2");
    
  • 它将每2分钟发送10个请求

    2.使用内置的
    Trait ThrottlesLogins

    在loginController中添加
    throttleLogins trait
    ,并在登录方法中添加此行

    if ($this->hasTooManyLoginAttempts($request)) {
        $this->fireLockoutEvent($request);
        return $this->sendLockoutResponse($request);
    }
    
    if(attempt()) {
        $this->clearLoginAttempts($request);
    }else {
      $this->incrementLoginAttempts($request);
    }
    
    如果尝试成功,则在尝试方法中添加此行

    $this->clearloginattests($request)

    否则登录失败,请添加此项 处于else状态的线路


    $this->incrementLoginAttents($request)

    打开您的登录控制器

    App\Http\Controllers\Auth\LoginController.php
    
    并粘贴它

    protected $maxAttempts = 1;
    protected $decayMinutes = 1;
    

    您需要在控制器中使用
    ThrottlesLogins
    trait,然后可以通过属性
    maxtures
    /
    decayMinutes

    。。。。
    类TagController扩展控制器
    {
    使用节流登录;
    受保护的$maxAttempts=5;
    受保护的$DecyMinutes=1;
    ...
    
    打开App\Http\Controllers\Auth\AuthController.php并添加以下行:

    protected $maxLoginAttempts = 10; 
    protected $lockoutTime = 120; 
    

    查看Laravel附带的ThrottlesLogin特性和默认脚手架。您可以编写代码吗?您可以查看代码吗?谢谢!