achetibi/laravel-captcha

Laravel Captcha Package

Maintainers

Package info

github.com/achetibi/laravel-captcha

Type:package

pkg:composer/achetibi/laravel-captcha

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-04-15 23:29 UTC

This package is auto-updated.

Last update: 2026-04-15 23:57:36 UTC


README

Latest Version on Packagist Total Downloads Tests License

Laravel Captcha is a modern, lightweight, and extensible CAPTCHA package for Laravel. It provides a flexible and developer-friendly way to generate and validate CAPTCHA images, with support for multiple drivers and configurations.

โš ๏ธ This package is based primarily on the excellent mews/captcha package, with a redesigned architecture, improved testability, and modern Laravel support.

๐Ÿš€ Features

  • Simple and flexible CAPTCHA generation
  • Multiple configurations (default, flat, mini, inverse, math)
  • Support for GD and Imagick drivers
  • API-friendly responses (Base64 image output)
  • Built-in validation (session & API modes)
  • Fully configurable:
    • Length
    • Fonts
    • Colors
    • Backgrounds
    • Effects (blur, sharpen, contrast, etc.)
  • Math CAPTCHA support
  • Laravel-native integration:
    • Service Provider
    • Facade
    • Helper functions
  • Fully tested using Pest

๐Ÿ“ฆ Requirements

  • PHP >= 8.3
  • Laravel 12.x or 13.x

โ— Other Laravel versions are not supported

๐Ÿ“ฆ Installation

composer require achetibi/laravel-captcha

โš™๏ธ Configuration

Publish the configuration file:

php artisan vendor:publish --provider="LaravelCaptcha\CaptchaServiceProvider"

๐Ÿง  Basic Usage

Generate CAPTCHA (HTML response)

captcha();

Generate CAPTCHA (API / Base64)

captcha('default');

Get CAPTCHA image URL

captcha_src();

Get CAPTCHA HTML image

captcha_img('default', ['class' => 'captcha']);

Validate CAPTCHA (session-based)

captcha_check($value);

Validate CAPTCHA (API-based)

captcha_api_check($value, $key);

Check CAPTCHA status

captcha_enabled();
captcha_disabled();

โš™๏ธ Configuration Options

Example configuration:

'default' => [
    'length' => 6,
    'width' => 345,
    'height' => 65,
    'quality' => 90,
    'math' => false,
    'expire' => 60,
    'encrypt' => false,
],

๐Ÿ–ผ Available Presets

  • default
  • flat
  • mini
  • inverse
  • math

๐Ÿ–ผ Image Drivers

The package supports two image drivers:

  • GD (default)
  • Imagick

Driver Configuration

CAPTCHA_DRIVER=gd

or

CAPTCHA_DRIVER=imagick

Driver Fallback

If imagick is selected but not installed, the package will automatically fallback to GD.

๐Ÿงช Testing

Run the test suite:

composer test

The package includes:

  • Unit tests
  • Feature tests
  • Driver validation tests (GD / Imagick)
  • Exception handling tests
  • Helper and facade tests

๐Ÿงฑ Architecture

The package is structured around:

  • Captcha core service
  • Laravel Service Container binding
  • Facade for convenient access
  • Global helper functions

โš ๏ธ Important Notes

  • CAPTCHA is single-use (invalidated after validation)
  • Cache is used for expiration handling
  • Session is used for standard validation
  • API mode does not rely on session

๐Ÿ”’ Security

  • Values are hashed using Laravelโ€™s Hash Manager
  • Optional encryption using Laravel Crypt
  • One-time validation prevents replay attacks

๐Ÿ“Œ Roadmap

  • Multiple configurations
  • GD / Imagick support
  • API validation
  • Full test coverage
  • Custom driver support
  • WebP / AVIF support
  • Rate limiting integration

๐Ÿ™ Credits

๐Ÿ“„ License

The MIT License (MIT). See LICENSE.md for full license text.