Download the PHP package mrtolouei/laravel-math-captcha without Composer
On this page you can find all versions of the php package mrtolouei/laravel-math-captcha. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mrtolouei/laravel-math-captcha
More information about mrtolouei/laravel-math-captcha
Files in mrtolouei/laravel-math-captcha
Package laravel-math-captcha
Short Description Single-use CAPTCHA for Laravel with anti-replay protection
License MIT
Informations about the package laravel-math-captcha
Laravel Math CAPTCHA
A stateless, lightweight math-based CAPTCHA package for Laravel that generates a simple arithmetic challenge as an image and verifies it via signed payloads.
No database, cache, or filesystem is required.
Table of contents
- Features
- Requirements
- Installation
- Configuration
- Usage
- Example Controller
- Testing
- Advanced Usage
- Security Notes
- Contributions
-
License
Features
- Stateless: no DB, cache, or filesystem dependency.
- Uses Laravel APP_KEY for secure HMAC signing.
- Configurable math range and image appearance.
- Simple one-time-use CAPTCHA (answer embedded in signed hash).
- Ready for Laravel 10+.
- Fully testable with PHPUnit.
Requirements
- PHP ≥ 8.1
- Laravel ≥ 10
- GD extension enabled (
php-gd) - Composer
Installation
Install via Composer:
Publish configuration file:
This will create:
Configuration
config/captcha.php contains two main sections:
Image
Math Expression
- Increasing the
min/maxrange makes CAPTCHA harder. - You can also use
.envfor environment-specific values.
Usage
Generating a CAPTCHA
Display in Blade
Verifying CAPTCHA
⚠ Note: This CAPTCHA is stateless, so there is no anti-replay mechanism. Each CAPTCHA is single-use in logic only; after verification, the hash can be reused unless you implement additional storage/cache.
Example Controller
Testing
This package uses PHPUnit 10 and Orchestra Testbench for Laravel integration.
Run tests:
Unit Tests Covered
- CAPTCHA generation returns valid image and hash.
- Correct answers pass verification.
- Wrong answers fail verification.
- Tampered hashes fail verification.
- Math expression respects configured
min/max.
Advanced Usage
- Customize image width, height, font, and colors via config.
-
Adjust math difficulty by setting
.envvariables: - Extend
CaptchaManagerto implement custom operators (e.g., multiplication).
Security Notes
- The security of this CAPTCHA relies on Laravel
APP_KEYsecrecy. - It is stateless: you may want to implement replay prevention using cache or DB if required.
- Increasing math range improves bot-resistance but may reduce readability.
Contributions
PRs, issues, stars are welcome!
- For bugs: open a GitHub issue.
- For features: fork and submit a PR.
- Follow PSR-12 coding style.
License
This package is open-sourced software licensed under the MIT license.
All versions of laravel-math-captcha with dependencies
illuminate/support Version ^10.0|^11.0
illuminate/cache Version ^10.0|^11.0
ext-gd Version *