You can create something simple, like the class below, to help you prevent this:
class Login { public function attempt($credentials) { if ( ! $user = User::where('email' => $credentials['email'])->first()) { //throw new Exception user not found } $user->login_attempts++; if ($user->login_attempts > 2) { if (Carbon::now()->diffInSeconds($user->last_login_attempt) < 60) { //trow new Exception to wait a while } $user->login_attempts = 0; } if ( ! Auth::attempt($credentials)) { $user->last_login_attempt = Carbon::now(); $user->save(); //trow new Exception wrong password } $user->login_attempts = 0; $user->save(); return true; } }
Or you can go with a package like Sentry , which controls throttling for you. Sentry is an open source.
source share