php - Laravel:在自定义登录中集成 Throttle

标签 php laravel validation laravel-5.4 throttling

没有使用laravel默认的LoginController如何集成laravel throttle?

这是我的 Controller :

  use AuthenticatesUsers;

  //function for login
  public function login(Request $requests){
    $username = $requests->username;
    $password = $requests->password;

    /**to login using email or username**/
    if(filter_var($username, FILTER_VALIDATE_EMAIL)) {

      Auth::attempt(['email' => $username, 'password' => $password]);
    } else {

      Auth::attempt(['username' => $username, 'password' => $password]);
    }


    if(Auth::check()){
      if(Auth::user()->type_user == 0){

        return view('users.dashboard');

      }
      else{
        return view('admin.dashboard');
      }
    }
    else{

      return Redirect::back()->withInput()->withErrors(['message'=>$login_error],'login');

    }
  }

我想限制失败的登录,但我似乎无法使用我自己的 Controller 使其工作。你们能帮帮我吗?

最佳答案

在您的方法中添加以下代码。把它放在第一位

// If the class is using the ThrottlesLogins trait, we can automatically throttle
// the login attempts for this application. We'll key this by the username and
// the IP address of the client making these requests into this application.
if ($this->hasTooManyLoginAttempts($request)) {
    $this->fireLockoutEvent($request);
    return $this->sendLockoutResponse($request);
}

现在在登录失败的地方添加如下代码。这将增加失败的尝试次数。

$this->incrementLoginAttempts($request);

成功登录后,添加以下代码以使其重置。

$this->clearLoginAttempts($request);

关于php - Laravel:在自定义登录中集成 Throttle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45180537/

相关文章:

javascript - 将 CSS 应用于一些用 PHP 定义的 div

mysql - 如何在eShop中使用ElasticSearch进行产品搜索(过滤)?

Eclipse 对 JSF 文件中的 EL 表达式给出了太多错误和警告

php - Laravel orderBy 与列值

Laravel 5.6 - 未捕获的运行时异常 : A facade root has not been set

c# - WPF 如何在文本框中使用验证规则而不创建额外的属性以绑定(bind)到对话框中?

javascript - 在 AngularJs 中处理输入验证?

php - Codeigniter 的 activerecord set() 方法将我的值视为列名

PHP - 将 mysql 时间戳转换为显示网格

php - 为什么一个刚刚定义的array of array count = 1?