-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
177 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
<?php | ||
|
||
return [ | ||
'max_attempts' => env('MAX_LOGIN_ATTEMPTS', 10), | ||
'max_attempts_user' => env('MAX_LOGIN_ATTEMPTS_USER', 10), | ||
'max_attempts_ip' => env('MAX_LOGIN_ATTEMPTS_IP', 20), | ||
'lockout_duration_user' => env('LOCKOUT_DURATION_USER', 15 * 60), | ||
'lockout_duration_ip' => env('LOCKOUT_DURATION_IP', 60 * 60 * 24 * 7), | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Mralston\Lockout\Console; | ||
|
||
use Illuminate\Console\Command; | ||
use Mralston\Lockout\Models\AuthFailure; | ||
|
||
class Prune extends Command | ||
{ | ||
protected $signature = 'lockout:prune'; | ||
|
||
protected $description = 'Prunes stale authentication failure records.'; | ||
|
||
public function handle() | ||
{ | ||
AuthFailure::prune(); | ||
|
||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Mralston\Lockout\Listeners; | ||
|
||
use Illuminate\Auth\Events\Attempting; | ||
use Illuminate\Foundation\Auth\AuthenticatesUsers; | ||
use Illuminate\Support\Carbon; | ||
use Illuminate\Support\Facades\Auth; | ||
use Mralston\Lockout\Models\AuthFailure; | ||
|
||
class AuthAttempted | ||
{ | ||
use AuthenticatesUsers; | ||
|
||
public function handle(Attempting $event) | ||
{ | ||
// Determine the username property on the user model | ||
$username_field = $this->username(); | ||
|
||
// Fetch the maximum number of login attempts per user and per IP address | ||
$max_attempts_user = config('lockout.max_attempts_user'); | ||
$max_attempts_ip = config('lockout.max_attempts_ip'); | ||
|
||
// Determine the timescale within which max login attempts shouldn't be exceeded | ||
$lockout_duration_user = config('lockout.lockout_duration_user'); | ||
$lockout_duration_ip = config('lockout.lockout_duration_ip'); | ||
|
||
if (!empty($lockout_duration_user)) { | ||
$user_since = Carbon::now()->subSeconds($lockout_duration_user); | ||
} | ||
|
||
if (!empty($lockout_duration_ip)) { | ||
$ip_since = Carbon::now()->subSeconds($lockout_duration_ip); | ||
} | ||
|
||
// Lockout if client IP has made too many attempts | ||
if (AuthFailure::countIpFailures(request()->ip(), $ip_since ?? null) >= $max_attempts_ip) { | ||
abort(403, 'Too many failed attempts'); | ||
} | ||
|
||
// Lockout if username has had too many failures | ||
if (AuthFailure::countEmailFailures($event->credentials[$username_field], $user_since ?? null) >= $max_attempts_user) { | ||
Auth::logout(); | ||
|
||
abort(403, 'Too many failed attempts'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters