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 關注
- 195 瀏覽
添加回答
舉報