aseqbase / captcha
CAPTCHA Plugin for aseqbase - Image generator CAPTCHA acceptor with admin panel
No longer found in upstream repository
Requires
- php: >=8.1
- ext-gd: *
- aseqbase/aseqbase: ^1.0
Requires (Dev)
- phpunit/phpunit: ^10.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Image generator CAPTCHA acceptor with admin panel for aseqbase website.
Features
- Image CAPTCHA: Generate CAPTCHA images with configurable noise, distortion, and character sets
- Admin Panel: Manage CAPTCHA configurations and target forms
- Form Integration: Automatically inject CAPTCHA into targeted forms
- Session Management: Secure CAPTCHA session handling with expiry
- Multiple Types: Support for image, math, and text CAPTCHAs
- Unicode Support: Customizable allowed character sets including Unicode
Installation
composer require aseqbase/captcha
Or install via aseqbase plugin manager.
Database Tables
The plugin creates three tables:
Captcha_Config- CAPTCHA configurationsCaptcha_Target- Form targeting rulesCaptcha_Session- Generated CAPTCHA sessions
Configuration
The plugin can be configured via the admin panel at /administrator/captcha/configs or by modifying the plugin properties in model/plugin/Captcha.php:
// Default CAPTCHA settings $DefaultType = "image"; // image, math, text $DefaultWidth = 200; $DefaultHeight = 80; $DefaultFontSize = 30; $DefaultNoiseLevel = 3; // 0-5 $DefaultDistortionLevel = 2; // 0-3 $DefaultLength = 5; // Code length $DefaultExpiryMinutes = 10; // Session expiry $DefaultAllowedChars = null; // JSON array, defaults to A-Z $CaseSensitive = false; $AutoValidate = true;
Admin Panel
Access the admin panel at:
- Configurations:
/administrator/captcha/configs- Manage CAPTCHA configurations - Target Forms:
/administrator/captcha/targets- Define which forms use CAPTCHA - Test Target:
/administrator/captcha/test-target- Test target matching
Target Types
- Global - Applies to all forms
- Selector - CSS selector to match form elements
- URL - URL pattern matching (supports fnmatch patterns)
Usage
Basic Usage in Forms
The plugin automatically integrates with forms based on admin configuration. For manual usage:
use MiMFa\Module\Captcha\Captcha; $captcha = new Captcha("default"); echo $captcha->Handle(); // Renders CAPTCHA field
Custom Character Sets
// Numbers only $captcha = new Captcha("default", range(0, 9)); // Unicode (Persian/Arabic + English) $chars = array_merge(range('A', 'Z'), range('أ', 'ي'), range('0', '9')); $captcha = new Captcha("default", $chars);
Validation
// From form submission if (Captcha::ValidateFromPost()) { // Valid CAPTCHA } // Manual validation $captcha = new Captcha("default"); if ($captcha->validate($inputCode, $sessionId)) { // Valid CAPTCHA }
AJAX Refresh
// Refresh CAPTCHA image $('.captcha-refresh').on('click', function() { var img = $('#captcha-img'); var src = img.attr('src').split('?')[0]; img.attr('src', src + '?' + Date.now()); });
Routes
GET /captcha/image/{id}- CAPTCHA imagePOST /captcha/refresh- Generate new CAPTCHAPOST /captcha/validate- Validate CAPTCHAGET /captcha/test- Test pageGET /captcha/demo- Demo page
API
Module: MiMFa\Module\Captcha\Captcha
| Method | Description |
|---|---|
__construct($configName, $allowedChars) |
Create CAPTCHA instance |
loadConfig() |
Load configuration from database |
generateSession() |
Generate new CAPTCHA session |
generateCode() |
Generate random code |
getImageUrl() |
Get CAPTCHA image URL |
validate($inputCode, $sessionId) |
Validate CAPTCHA code |
getImage() |
Output CAPTCHA image |
GetInner() |
Get HTML for form integration |
GetScript() |
Get client-side JavaScript |
ValidateFromPost($data) |
Static validation from POST |
CleanExpired() |
Static cleanup of expired sessions |
Component: MiMFa\Module\Captcha\CaptchaImage
| Method | Description |
|---|---|
HandleImage($sessionId) |
Handle image request |
OutputImage($code, $config) |
Generate and output image |
Validate($data) |
Validate CAPTCHA |
CleanExpired() |
Clean expired sessions |
Plugin: MiMFa\Plugin\Captcha
| Method | Description |
|---|---|
getConfig($name) |
Get configuration by name |
getAllConfigs() |
Get all active configurations |
getTargets($configId) |
Get targets for configuration |
getConfigForForm($form) |
Find matching config for form |
Validate($data) |
Static validation |
cleanExpired() |
Clean expired sessions |
maybeCleanExpired() |
Probabilistic cleanup |
Requirements
- PHP >= 8.1
- GD extension
- aseqbase >= 1.0
License
MIT License
Author
Mohammad Fathi - https://aseqbase.ir