Initial commit
This commit is contained in:
26
api/app/Http/Middleware/ThrottlePasswordVerification.php
Normal file
26
api/app/Http/Middleware/ThrottlePasswordVerification.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class ThrottlePasswordVerification
|
||||
{
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
$key = 'password-verify:'.$request->ip();
|
||||
|
||||
if (RateLimiter::tooManyAttempts($key, 5)) {
|
||||
$seconds = RateLimiter::availableIn($key);
|
||||
|
||||
return response()->json([
|
||||
'message' => "Too many attempts. Please try again in {$seconds} seconds.",
|
||||
], 429);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user