当前位置: 首页 > news >正文

张家港早晨网站制作新浪网今日乌鲁木齐新闻

张家港早晨网站制作,新浪网今日乌鲁木齐新闻,自己做一元夺宝网站,长沙手机模板建站在用户身份验证的情况下,Laravel 具有内置的身份验证系统。我们可以根据要求轻松修改它。身份验证中包含的功能之一是Throttling. 为什么我们需要throttling保护? 基本上,throttling是用来保护暴力攻击的。它将在一定时间内检查登录尝试。在短…

在用户身份验证的情况下,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属性更改允许的最大尝试次数和限制的分钟数。在这里,您可以找到完整的代码。

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登录失败次数限制内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

http://www.mmbaike.com/news/32515.html

相关文章:

  • 网站维护运营优化公司广告精准推广平台
  • 怎样在微信做产品网站东莞网络推广公司
  • 北票网站建设杭州seo公司
  • 镇江网站建设价格营销方式和渠道有哪些
  • 长沙专业做网站公司网站seo排名优化
  • 帮人做钓鱼网站的人荆门今日头条新闻发布
  • 网页游戏广告平台网站建设十大互联网广告公司
  • 制作营销网站模板免费下载优化设计答案大全英语
  • 旅游网站建设公司2021百度最新收录方法
  • 发布外链网站seo的方法有哪些
  • 企业网站设计营销青岛网站建设公司排名
  • 用asp.net做网站网上推广平台有哪些
  • 网站如何做视频的软件2024北京又开始核酸了吗今天
  • wordpress menu css广州seo服务外包
  • 网上商店系统设计软件优化
  • 给千图网等网站做设计赚钱吗西安百度代运营
  • 做推广秒杀网站互联网推广工作好做吗
  • 免费域名注册方式百度快照优化排名
  • 网站干什么的seo快速排名利器
  • 公司网站制作合同市场推广计划书
  • 建设第二个北京在哪里网站快速优化排名官网
  • dede做的网站被植入广告百度一下你就知道官网网页
  • 只有做推广才能搜索到网站吗网络营销手段有哪四种
  • 网站经常被黑搜狐综合小时报2022113011
  • WordPress搭建流媒体网站百度视频推广
  • 中国移动一键登录九江seo公司
  • 网站架构怎么看网站推广的方法有哪些?
  • 公明网站建设百度学术搜索
  • 手机网站开发 c定制企业网站建设制作
  • 信贷员在哪个网站做推广东莞网站推广营销