如何解决登录失败太多后,如何在laravel中将lockoutTime时间从秒增加到分钟?
下面是我的LoginController方法在三次失败的登录尝试之后,会显示一条消息“ 登录尝试太多。请在9秒内重试。”。我想将时间增加到10分钟。
我的登录控制器和构造器
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Http\Request;
use Auth;
use App\User;
class LoginController extends Controller
{
use AuthenticatesUsers;
protected $auth;
protected $lockoutTime;
protected $maxLoginAttempts;
protected $redirectTo = '/';
public function __construct(Guard $auth)
{
$this->middleware('guest',['except' => 'logout']);
$this->auth = $auth;
$this->lockoutTime = 1;
$this->maxLoginAttempts = 3;
}
}
登录方法:
public function login(Request $request)
{
$this->validateLogin($request);
if ($this->hasTooManyLoginAttempts($request)) {
$this->fireLockoutEvent($request);
return $this->sendLockoutResponse($request)
}else{
$username = $request->get('email');
$password = $request->get('password');
$remember = $request->get('remember');
if ($this->auth->attempt([
'email' => $username,'password' => $password,'status' => 1,],$remember == 1 ? true : false)) {
Auth::logoutOtherDevices($password);
$request->session()->regenerate();
$this->clearLoginAttempts($request);
if (Auth::check() && Auth::user()->roles()->first()->name == 'admin') {
return redirect('/admin/dashboard');
} else {
return redirect('/institute/inst-dashboard');
}
}else {
$this->incrementLoginAttempts($request);
return redirect()->back()
->with('error','Incorrect username or password.')
->with('status','danger')
->withInput();
}
}
}
方法太多
protected function hasTooManyLoginAttempts(Request $request)
{
return $this->limiter()->tooManyAttempts(
$this->throttleKey($request),$this->maxLoginAttempts,$this->lockoutTime
);
}
解决方法
在您的string
中,您可以添加两个属性:
__main__
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。