Search by

aseqbase / captcha

mimfa

CAPTCHA Plugin for aseqbase - Image generator CAPTCHA acceptor with admin panel

Package info

github.com/aseqbase/captcha

Type:aseqbase-plugin

pkg:composer/aseqbase/captcha

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v8.0 2026-12-01 15:12 UTC
No longer found in upstream repository

This package is auto-updated.

Last update: 2026-12-02 14:29:30 UTC


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 configurations
  • Captcha_Target - Form targeting rules
  • Captcha_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

  1. Global - Applies to all forms
  2. Selector - CSS selector to match form elements
  3. 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 image
  • POST /captcha/refresh - Generate new CAPTCHA
  • POST /captcha/validate - Validate CAPTCHA
  • GET /captcha/test - Test page
  • GET /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