2 回答
TA贡献1815条经验 获得超10个赞
您将需要为用户创建一个列来计算他们不成功的登录尝试。每次不成功的尝试时,您都会增加该值,并在达到特定限制时阻止用户。
如果登录成功,则将计数器设置为0。
TA贡献1946条经验 获得超4个赞
我测试了一下,是正确的。
首先在您的EventServiceProvider 中创建两个事件侦听器。 登录成功和登录失败
protected $listen = [
Registered::class => [
SendEmailVerificationNotification::class,
],
'Illuminate\Auth\Events\Login' => [
'App\Listeners\SuccessfulLogin',
],
'Illuminate\Auth\Events\Failed' => [
'App\Listeners\FailedLogin',
],
];
在成功登录中:
public function handle(Login $event)
{
$event->user->user_last_login_date = Carbon::now();
$event->user->unsuccessful_login_count = 0;
$event->user->save();
}
在登录失败中:
$event->user->unsuccessful_login_count += 1 ;
$unsuccessful_count = General::first()->max_attempts;
if ($event->user->unsuccessful_login_count == $unsuccessful_count ) {
$event->user->three_attempt_timestamp = Carbon::now()->toDateString();
}
if ($event->user->unsuccessful_login_count > $unsuccessful_count ) {
$event->user->is_block = 1;
}
$event->user->save();
- 2 回答
- 0 关注
- 142 浏览
添加回答
举报