djimmy/laravel-captcha

A simple Laravel package for generating CAPTCHA images.

v1.0.4 2024-12-20 13:00 UTC

This package is auto-updated.

Last update: 2025-06-20 14:02:48 UTC


README

Build Status Total Downloads Latest Stable Version License

About Laravel Captcha

Laravel Captcha is a simple and customizable package to integrate CAPTCHA functionality into your Laravel application. It provides an easy-to-use API for generating CAPTCHA codes and validating user inputs, helping to protect your application from bots and spam.

Features

  • Generates customizable CAPTCHA images.
  • Validates CAPTCHA inputs.
  • Clears CAPTCHA sessions automatically.
  • Easily integrates with Laravel applications.

Installation

Install the package using Composer:

composer require djimmy/captcha

Usage

  1. Add the Service Provider (if not auto-discovered):

    // config/app.php
    'providers' => [
        Djimmy\Captcha\CaptchaServiceProvider::class,
    ];
  2. Publish the Config File:

    php artisan vendor:publish --provider="Djimmy\Captcha\CaptchaServiceProvider"
  3. Generate a CAPTCHA Image:

    In your controller:

    use Djimmy\Captcha\CaptchaService;
    
    public function showCaptcha(CaptchaService $captchaService)
    {
        return $captchaService->generateCaptcha();
    }
  4. Validate CAPTCHA:

    use Illuminate\Http\Request;
    use Djimmy\Captcha\CaptchaService;
    
    public function validateCaptcha(Request $request, CaptchaService $captchaService)
    {
        $isValid = $captchaService->validateCaptcha($request->input('captcha'));
    
        if ($isValid) {
            // CAPTCHA is valid
        } else {
            // CAPTCHA is invalid
        }
    }
  5. Clear CAPTCHA:

    $captchaService->clearCaptcha();

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue on GitHub.

License

This package is open-sourced software licensed under the MIT license.