好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > Laravel登錄失敗次數限制的實現方法

Laravel登錄失敗次數限制的實現方法

熱門標簽:地圖標注符號樣式有 廈門400電話辦理選易號網 臨沂crm外呼系統平臺 梧州市機器人外呼系統怎么樣 菏澤語音外呼系統運營商 天客通地圖標注 電子地圖標注怎么修改 如何在世界地圖標注 公司外呼系統中心

在用戶身份驗證的情況下,Laravel 具有內置的身份驗證系統。我們可以根據要求輕松修改它。身份驗證中包含的功能之一是Throttling.

為什么我們需要throttling保護?

基本上,throttling是用來保護暴力攻擊的。它將在一定時間內檢查登錄嘗試。在短登錄中,throttling會計算用戶或機器人嘗試失敗的登錄嘗試次數。

使用自定義登錄實現限制

默認情況下,在內置身份驗證控制器中實現限制。但是,如果我們需要實現它到自定義登錄呢?

實現自定義登錄限制非常容易。首先,我們必須將ThrottlesLogins trait包含到您的控制器中。

use Illuminate\Foundation\Auth\ThrottlesLogins;

現在,將此ThrottlesLogins trait 加到控制器中。

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Foundation\Auth\ThrottlesLogins;
class AuthController extends Controller
{
 use ThrottlesLogins;
 ......

現在轉到用于對用戶進行身份驗證的方法。在我的例子中,我使用了 login() POST 方法。并粘貼以下代碼:

public function login(Request $request)
{
 // Authenticate Inputs
 $request->validate([
 'username' => 'required', 
 'password' => 'required|min:6|max:18'
 ]);
 // 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 (method_exists($this, 'hasTooManyLoginAttempts') 
 $this->hasTooManyLoginAttempts($request)) {
 $this->fireLockoutEvent($request);
 return $this->sendLockoutResponse($request);
 }
 
 .......

首先,我們驗證了用戶提交的輸入,然后實現了hasTooManyLoginAttempts() 方法。此方法將檢查用戶在某個時間是否執行過一定數量的失敗嘗試,然后系統將通過sendLockoutResponse()  方法阻止該用戶。

現在,我們必須通過incrementLoginAttempts()方法指示對ThrottlesLogins trait的失敗登錄嘗試。

if( Auth::attempt(['username' => $username, 'password' => $password]) ){
 // Redirect to appropriate dashboard 
}
else {
 // If the login attempt was unsuccessful we will increment the number of attempts
 // to login and redirect the user back to the login form. Of course, when this
 // user surpasses their maximum number of attempts they will get locked out.
 $this->incrementLoginAttempts($request);
 return redirect()->back()
  ->withInput($request->all())
  ->withErrors(['error' => 'Please check your username / password.']);
}

您還可以通過$maxAttempts和$decayMinutes屬性更改允許的最大嘗試次數和限制的分鐘數。在這里,您可以找到完整的代碼。

?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Foundation\Auth\ThrottlesLogins;
class AuthController extends Controller
{
 use ThrottlesLogins;
 /**
  * The maximum number of attempts to allow.
  *
  * @return int
  */
 protected $maxAttempts = 5;
 /**
  * The number of minutes to throttle for.
  *
  * @return int
  */
 protected $decayMinutes = 1;
 public function login(Request $request)
 {
  // Authenticate Inputs
  $request->validate([
   'username' => 'required', 
   'password' => 'required|min:6|max:18'
  ]);
  // 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 (method_exists($this, 'hasTooManyLoginAttempts') 
   $this->hasTooManyLoginAttempts($request)) {
   $this->fireLockoutEvent($request);
   return $this->sendLockoutResponse($request);
  }
  $username = $request->username;
  $password = $request->password;
  
  if( Auth::attempt(['username' => $username, 'password' => $password]) ){
   // Redirect to appropriate dashboard 
  }
  else {
   // If the login attempt was unsuccessful we will increment the number of attempts
   // to login and redirect the user back to the login form. Of course, when this
   // user surpasses their maximum number of attempts they will get locked out.
   $this->incrementLoginAttempts($request);
   return redirect()->back()
    ->withInput($request->all())
    ->withErrors(['error' => 'Please check your username / password.']);
  }
 }
}
Related Posts:

總結

到此這篇關于Laravel登錄失敗次數限制的文章就介紹到這了,更多相關Laravel登錄失敗次數限制內容請搜索腳本之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • Laravel實現用戶注冊和登錄
  • Laravel搭建后臺登錄系統步驟詳解
  • Laravel 自帶的Auth驗證登錄方法
  • Laravel 5.4重新登錄實現跳轉到登錄前頁面的原理和方法
  • Laravel重寫用戶登錄簡單示例
  • 利用Laravel事件系統如何實現登錄日志的記錄詳解
  • SSO單點登錄的PHP實現方法(Laravel框架)
  • Laravel5.2使用Captcha生成驗證碼實現登錄(session巨坑)
  • php的laravel框架快速集成微信登錄的方法
  • laravel5.2實現區分前后臺用戶登錄的方法

標簽:迪慶 雞西 貴陽 郴州 瀘州 白城 綿陽 黃石

巨人網絡通訊聲明:本文標題《Laravel登錄失敗次數限制的實現方法》,本文關鍵詞  Laravel,登錄,失敗,次數,限制,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《Laravel登錄失敗次數限制的實現方法》相關的同類信息!
  • 本頁收集關于Laravel登錄失敗次數限制的實現方法的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 扒开老师的湿润小泬喷白浆网站| 国产精品夜夜爽7777777| 美女被日在线观看| 91??丝袜在线播放| ??爱情岛亚洲论坛??| 108啪啪姿势大全动图| 日本肉漫| 香港三级午夜理伦三级三| 嗯~好大?用力?深一点孕妇| 欧美日韩国产在线一区| 台湾三级艳史之欲乱太子| 好痛~不要轻一点的视频| 女主性瘾放荡的快穿np文| 金梅瓶禁传三级在线观看全集| 一级毛片在线看在线播放| 后进圆润翘臀极品大屁股韩国 | 特黄Av一级AAA片日本取精| 国产欧美日韩一区二区三区视频| 噜噜噜久久亚洲精品色情| 性8电台畅听网倾听网| 俄罗斯aaaaa一级毛片| 欧美18一20男同69GAy| 小妖精舒服吗+肉+高H视频| 十分钟在线观看高清www| 好紧好大爽好多水| 男女啪啪做爰高潮全过有多重意思| 诱人的女邻居| gc是什么意思| 公交车上的诗请1h| 色台湾色综合网站| 今天躁天天躁天天躁2022| 国产精品亚洲AV色欲一区二区三区| 杨幂哭着说不能深了黄杰安庆政法委的最新视频| 国产美女做a免费视频软件 | 羞羞视频网站免费| 师兄啊师兄在线观看| 美女校花把我夹的好爽故事| 丰满少妇A片免费观看潮喷桃花| 皇上紫黑粗硕好大烫死奴婢好爽| 日本A片一级二级全过程| 久久这里九九九热精品九热无码免费|