Download the PHP package joe-nassar-tech/laravel-exponential-lockout without Composer
On this page you can find all versions of the php package joe-nassar-tech/laravel-exponential-lockout. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download joe-nassar-tech/laravel-exponential-lockout
More information about joe-nassar-tech/laravel-exponential-lockout
Files in joe-nassar-tech/laravel-exponential-lockout
Package laravel-exponential-lockout
Short Description Laravel package for implementing exponential lockout on failed authentication attempts with configurable contexts
License MIT
Homepage https://github.com/joe-nassar-tech/laravel-exponential-lockout
Informations about the package laravel-exponential-lockout
Laravel Exponential Lockout
A comprehensive Laravel package for implementing exponential lockout functionality on failed authentication attempts with configurable contexts and response handling.
Features
- 🎯 Perfect Exponential Lockout: Grace attempts system - exactly 1 attempt allowed after each lockout period
- ✅ 100% Automatic Middleware: Zero code changes needed - just add middleware to routes
- ✅ Smart Delay Progression: Configurable delays (default: 1min → 5min → 15min → 30min → 2hr → 6hr → 12hr → 24hr)
- ✅ Configurable Free Attempts: Set how many attempts before first lockout (default: 3)
- ✅ Multiple Contexts: Different rules for
login,otp,admin,pin, etc. - ✅ Context Inheritance: Reusable templates for consistent security policies
- ✅ Flexible Key Extraction: Track by email, phone, username, IP, or custom logic
- ✅ Auto-Detection: Automatically detects 4xx/5xx failures and 2xx success
- ✅ Manual API Control: Full programmatic control when needed
- ✅ Smart Response Handling: Auto-detect JSON/redirect responses with proper headers
- ✅ Persistent Attempt History: Remembers failures across lockout periods
- ✅ Cache-Based Storage: Uses Laravel's cache system (Redis, File, Database, etc.)
- ✅ Artisan Commands: CLI tools for lockout management and debugging
- ✅ Blade Directives: Template helpers for lockout status display
- ✅ Laravel 9-12+ Compatible: Full support for all modern Laravel versions
Installation
Install via Composer:
Publish the configuration file:
Configuration
The package comes with sensible defaults, but you can customize everything in config/exponential-lockout.php:
How It Works
🎯 Perfect Exponential Lockout Behavior
The package implements a grace attempt system that provides exactly 1 attempt after each lockout period:
| Attempt | Result | Behavior |
|---|---|---|
| 1st-3rd ❌ | ✅ Free attempts | No lockout (configurable with min_attempts) |
| 4th ❌ | 🚫 Block 60s | First lockout (using default delays) |
| After 60s | 🎁 1 grace attempt | Exactly 1 try allowed |
| Grace ❌ | 🚫 Block 300s | Second lockout (5 minutes) |
| After 300s | 🎁 1 grace attempt | Exactly 1 try allowed |
| Grace ❌ | 🚫 Block 900s | Third lockout (15 minutes) |
| Any Success ✅ | 🔄 Complete Reset | Back to 3 free attempts |
🔑 Key Features:
- Configurable free attempts (default: 3) before first lockout
- Progressive delays that increase exponentially
- Grace attempts - exactly 1 attempt allowed after each lockout expires
- Automatic reset on any successful authentication
- Persistent memory - remembers attempt history across sessions
Basic Usage
1. Middleware Protection
Protect routes with middleware:
2. Manual Lockout Management
Use the Lockout facade for manual control:
3. OTP Verification Example
Advanced Usage
Custom Key Extraction
Define custom key extractors in the config:
Custom Response Handling
Implement custom response logic:
Check Lockout Status
Check if a user is locked out before processing:
Get Detailed Lockout Information
Blade Directives
Use Blade directives in your templates:
Artisan Commands
Clear Specific Lockout
Clear All Lockouts for Context
API Reference
Lockout Facade Methods
Context Configuration
Each context can be configured independently or inherit from templates:
Using Templates (Recommended)
Direct Configuration
Available Key Extractors
email- Extract fromemailinput fieldphone- Extract fromphoneinput fielduser_id- Extract from authenticated user IDip- Use client IP addressusername- Extract fromusernameinput field- Custom callable - Define your own extraction logic
Response Modes
auto- Auto-detect JSON or redirect based on requestjson- Always return JSON responseredirect- Always redirect to specified routecallback- Use custom callback function
Delay Sequences
Default sequence provides exponential backoff:
Customize per context:
Error Handling
The package includes comprehensive error handling:
Cache Considerations
Cache Store Selection
Configure the cache store in your config:
TTL Management
Cache entries automatically expire after lockout duration + 1 hour buffer.
Redis Optimization
For Redis, consider using a dedicated database:
Testing
The package includes comprehensive test coverage. Run tests with:
Testing Lockouts in Your App
Performance Considerations
- Cache Efficiency: Uses single cache key per context/user combination
- TTL Optimization: Automatic cleanup of expired lockouts
- Memory Usage: Minimal data storage per lockout entry
- Lookup Speed: O(1) cache lookups for lockout status
Security Best Practices
- Rate Limiting: Combine with Laravel's rate limiting for comprehensive protection
- IP Tracking: Use IP-based lockouts for anonymous endpoints
- Context Separation: Use different contexts for different authentication methods
- Cache Security: Secure your cache store (Redis AUTH, etc.)
- Key Hashing: Keys are automatically hashed for privacy
Troubleshooting
Common Issues
Lockouts not working:
- Check context is enabled in config
- Verify cache store is working
- Ensure middleware is applied to routes
Lockouts not clearing:
- Check cache connectivity
- Verify context and key match exactly
- Use Artisan command to manually clear
Wrong response format:
- Check
response_modein context config - Verify request headers for JSON detection
- Test with custom response callback
Debug Mode
Enable debug logging:
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for details.
License
This package is open-sourced software licensed under the MIT license.
Changelog
See CHANGELOG.md for version history and updates.
Support
- Documentation: This README and inline code comments
- Issues: GitHub Issues for bug reports and feature requests
- Discussions: GitHub Discussions for questions and community support
About the Developer
Joe Nassar
Email: [email protected]
Made with ❤️ for the Laravel community
All versions of laravel-exponential-lockout with dependencies
illuminate/support Version ^9.0|^10.0|^11.0|^12.0
illuminate/cache Version ^9.0|^10.0|^11.0|^12.0
illuminate/console Version ^9.0|^10.0|^11.0|^12.0
illuminate/http Version ^9.0|^10.0|^11.0|^12.0