Lightpack Captcha System

Lighpack makes it painless to add CAPTCHA protection to your apps—whether you need a simple image challenge, Google reCAPTCHA, Cloudflare Turnstile, or a no-op for testing.


Supported Drivers

Driver Class Use Case
null NullCaptcha Testing/dev, disables CAPTCHA (always passes)
native NativeCaptcha Simple image CAPTCHA (no external API)
recaptcha GoogleReCaptcha Google reCAPTCHA v2 widget
turnstile CloudflareTurnstile Cloudflare Turnstile widget

Configuration

Please run following command to create config/captcha.php configuration file.

php console create:config --support=captcha

CaptchaInterface

All drivers implement:

// Render the challenge (HTML/image)
public function generate(): string;

// Validate user captcha response
public function verify(): bool;     

Usage Patterns

Rendering a CAPTCHA

echo captcha()->generate();

Verifying User Response

// In your form handler:
if (captcha()->verify()) {
    // Passed
} else {
    // Failed
}

Driver Details

NullCaptcha (Testing/Dev)

echo captcha()->generate(); // ''

captcha()->verify(); // always true

NativeCaptcha (Image-based)

// Configure image captcha settings
captcha()
    ->font('/path/to/font.ttf')
    ->width(200)
    ->height(60);

// In the form view
echo '<img src="' . captcha()->generate() . '" />';

// In form handler
if (captcha()->verify()) { 
    // Passed
}

GoogleReCaptcha

// Outputs Google recaptcha
echo captcha()->generate(); 

// In form handler
if (captcha()->verify()) {
    // passed
}

CloudflareTurnstile

// Outputs <div class="cf-turnstile" ...>
echo captcha()->generate(); 

// In form handler
if (captcha()->verify()) {
    // passed
}