Built-in Blade Components
The package includes ready-to-use Blade components for displaying rate limit messages. No need to create these
components yourself - they are automatically available after package installation.
Error Messages
Display rate limit errors when limits are exceeded:
{{-- Login Page Example --}}
<x-error-message field="rate_limit" :title="__('Login Temporarily Blocked')" class="my-4 p-4" />
{{-- Registration Page Example --}}
<x-error-message field="rate_limit" :title="__('Registration Temporarily Blocked')" class="my-4 p-4" />
{{-- Forgot Password Page Example --}}
<x-error-message field="rate_limit" :title="__('Password Reset Temporarily Blocked')" class="my-4 p-4" />
{{-- Two-Factor Authentication Page Example --}}
<x-error-message field="rate_limit" :title="__('Two-Factor Authentication Temporarily Blocked')" class="my-4 p-4" />
Lock-down timer
By default, when locked is applied, a countdown timer is displayed showing the remaining time until unblocking. You can
customize the countdown format by setting the RATE_LIMITING_SHOW_WAIT_COUNTER
property in your application .env file.
Default value is true
Warning Messages
Display proactive warnings when users are approaching limits:
{{-- Show warning when approaching rate limit --}}
<x-warning-message :title="__('Login Warning')" class="my-4 p-4" />
{{-- With custom message --}}
<x-warning-message message="Custom warning message" :title="__('Warning')" class="my-4 p-4" />
The warning component automatically displays session-based warnings when users are approaching their rate limits.
Complete Integration Example
Here's how to integrate both error and warning messages in an authentication form:
{{-- resources/views/auth/login.blade.php --}}
<form method="POST" action="{{ route('login') }}">
@csrf
{{-- Rate Limit Error Display --}}
<x-error-message field="rate_limit" :title="__('Login Temporarily Blocked')" class="my-4 p-4" />
{{-- Rate Limit Warning Display --}}
<x-warning-message :title="__('Login Warning')" class="my-4 p-4" />
{{-- Email Field --}}
<div class="mb-4">
<label for="email">{{ __('Email') }}</label>
<input type="email" name="email" id="email" required />
<x-error-message field="email" />
</div>
{{-- Password Field --}}
<div class="mb-4">
<label for="password">{{ __('Password') }}</label>
<input type="password" name="password" id="password" required />
<x-error-message field="password" />
</div>
{{-- Submit Button --}}
<button type="submit">{{ __('Login') }}</button>
{{-- Password Reset Link --}}
<a href="{{ route('password.request') }}">{{ __('Forgot Password?') }}</a>
</form>
Component Properties
Both components accept the following properties:
field
(error-message only): The error field name (default: '')
message
(warning-message only): Custom message to display (default: '')
title
: The title/heading for the message (default: null)
class
: CSS classes to apply (default: 'my-2 p-2')
Automatic Integration
The package automatically integrates with Laravel's authentication system and works seamlessly with or without Laravel
Fortify. No additional setup is required - rate limiting will be applied to:
- Registration attempts
- Login attempts
- Password reset requests
- Two-factor authentication attempts
Username Field Resolution
The package uses an intelligent hybrid approach to resolve username fields:
- Custom Resolver (Advanced): Define a custom callback for complex logic
- Fortify Integration (Automatic): Uses Fortify's username field if installed
- Configurable Field (Simple): Set
username_field
in config (default: 'email')
- Smart Fallback (Automatic): Tries common field names (email, username, login, etc.)
Message Customization
The system provides intelligent, context-aware messages that adapt based on the situation:
Error Message Examples
-
Login: "Too many login attempts with this username from your location. Please wait 5 minutes before trying again.
Consider resetting your password if you've forgotten it, or contact support if you believe this is an error."
-
Registration: "Too many registration attempts from your location. Please wait 3 minutes before trying again.
Please verify all required fields are filled correctly and try again later."
-
Two-Factor: "Too many two-factor authentication attempts for this session. Please wait 8 minutes before trying
again. If you're having trouble with your authenticator, try using a recovery code instead."
Warning Message Examples
-
Login Warning: "You have 2 attempt(s) remaining before a temporary lockout. If you've forgotten your password,
consider using the 'Reset Password' link below."
-
Registration Warning: "You have 1 attempt(s) remaining before a temporary lockout. Please double-check your
information before submitting."
-
Two-Factor Warning: "You have 2 attempt(s) remaining before a temporary lockout. Double-check your authenticator
app or recovery code."
Custom Messages
The system supports three types of customizable messages:
1. Error Messages
Error messages are shown when rate limits are exceeded:
# Basic error messages (shown when limits are exceeded)
RATE_LIMITING_REGISTER_EMAIL_MESSAGE="Too many registration attempts with this email. Please wait :minutes minutes."
RATE_LIMITING_LOGIN_USERNAME_IP_MESSAGE="Too many login attempts. Please wait :minutes minutes before trying again."
RATE_LIMITING_FORGOT_PASSWORD_EMAIL_MESSAGE="Too many password reset attempts. Please wait :minutes minutes."
RATE_LIMITING_TWO_FACTOR_SESSION_MESSAGE="Too many 2FA attempts. Please wait :minutes minutes."
2. Warning Messages
Warning messages are shown when users are approaching rate limits:
# Base warning message template
RATE_LIMITING_WARNING_BASE_MESSAGE="You have :attempts attempt(s) remaining before a temporary lockout."
# Context-specific warning suggestions
RATE_LIMITING_WARNING_LOGIN_SUGGESTION="If you've forgotten your password, consider using the 'Reset Password' link below."
RATE_LIMITING_WARNING_REGISTER_SUGGESTION="Please double-check your information before submitting."
RATE_LIMITING_WARNING_FORGOT_PASSWORD_SUGGESTION="Please verify the email address is correct."
RATE_LIMITING_WARNING_TWO_FACTOR_SUGGESTION="Double-check your authenticator app or recovery code."
3. Suggestion Messages
Suggestion messages are appended to error messages to provide helpful guidance:
# Login suggestions (based on attempt count)
RATE_LIMITING_LOGIN_HIGH_ATTEMPTS_SUGGESTION="Consider resetting your password if you've forgotten it, or contact support if you believe this is an error."
RATE_LIMITING_LOGIN_LOW_ATTEMPTS_SUGGESTION="Please double-check your email and password."
# Two-factor suggestions (based on attempt count)
RATE_LIMITING_TWO_FACTOR_HIGH_ATTEMPTS_SUGGESTION="If you're having trouble with your authenticator, try using a recovery code instead."
RATE_LIMITING_TWO_FACTOR_LOW_ATTEMPTS_SUGGESTION="Please check your authenticator app for the current code."
# Simple suggestions (same regardless of attempt count)
RATE_LIMITING_REGISTER_SUGGESTION="Please verify all required fields are filled correctly and try again later."
RATE_LIMITING_FORGOT_PASSWORD_SUGGESTION="Please ensure the email address is correct and check your spam folder for previous reset emails."
Message Placeholders
:minutes
- Automatically replaced with wait time in minutes (error messages)
:attempts
- Automatically replaced with remaining attempts count (warning messages)
Smart Suggestion Logic
The system automatically selects appropriate suggestions based on context:
- Login & Two-Factor: Uses different suggestions for high attempts (≥3) vs low attempts (<3)
- Registration & Forgot Password: Uses consistent suggestions regardless of attempt count
- Fallback: Provides default suggestions if specific ones aren't configured
User Experience Flow
Progressive User Feedback
The system provides a progressive feedback experience that guides users through rate limiting scenarios:
Normal Operation
- Successful attempts: No rate limiting messages shown
- Failed attempts: Standard validation errors displayed
Approaching Limits (2 or fewer attempts remaining)
- Warning displayed: "You have 2 attempt(s) remaining before a temporary lockout."
- Context-specific guidance: Appropriate suggestions based on the endpoint
- Proactive help: Encourages correct action before lockout
Rate Limit Exceeded
- Clear error message: Explains what happened and how long to wait
- Helpful suggestions: Context-aware guidance for resolution
- Recovery options: Suggests alternative actions (password reset, support contact)
Example User Journey (Login with 5 attempt limit)
Attempts 1-3: Normal login attempts with standard validation errors
↓
Attempt 4: Warning appears: "You have 2 attempts remaining before a temporary lockout.
If you've forgotten your password, consider using the 'Reset Password' link below."
↓
Attempt 5: Warning appears: "You have 1 attempt remaining before a temporary lockout.
If you've forgotten your password, consider using the 'Reset Password' link below."
↓
Attempt 6: Error appears: "Too many login attempts with this username from your location.
Please wait 1 minute before trying again. Consider resetting your password
if you've forgotten it, or contact support if you believe this is an error."
↓
Attempt 7: (after 1 minute wait) Error appears: "Please wait 2 minutes before trying again..."
↓
Attempt 8: (after 2 minute wait) Error appears: "Please wait 3 minutes before trying again..."
Benefits of Progressive Feedback
- Prevents frustration: Users get warnings before being locked out
- Reduces support burden: Clear guidance helps users self-resolve issues
- Maintains security: All security protections remain fully effective
- Improves conversion: Users are less likely to abandon the process
Monitoring and Logging
When RATE_LIMITING_LOG_VIOLATIONS=true
, the package logs detailed information about violations:
{
"message": "Rate limit exceeded for register:email: register:email:user@example.com",
"context": {
"wait_seconds": 180,
"attempts": 4,
"ip": "192.168.1.100",
"user_agent": "Mozilla/5.0...",
"limiter_type": "register",
"limit_type": "email",
"growth_strategy": "fibonacci"
}
}
Monitoring Best Practices
- Regular log review: Monitor for unusual patterns or attack attempts
- Alert configuration: Set up alerts for high violation rates
- Performance monitoring: Track cache usage and response times
- User feedback: Monitor support requests related to access issues
Performance Considerations
- Cache efficiency: Uses Laravel's cache system with optimized key structures
- Minimal overhead: Processing only occurs when limits are approached
- Memory management: Configurable maximum suspension times prevent indefinite cache growth
- Scalability: Designed to handle high-traffic applications
Security Best Practices
- Regular monitoring: Review logs for attack patterns and adjust limits accordingly
- Limit tuning: Fine-tune based on legitimate user behavior patterns
- HTTPS enforcement: Always use HTTPS to prevent session hijacking
- IP whitelisting: Consider whitelisting trusted IP ranges for administrative access
- Configuration review: Periodically review and update rate limiting configurations
- Incident response: Have procedures for quickly adjusting limits during attacks