PHPackages                             mohsenfathipour/captcha-generator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. mohsenfathipour/captcha-generator

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mohsenfathipour/captcha-generator
=================================

A Laravel package for generating CAPTCHA images.

v1.0.0(1y ago)06MITPHPPHP ^8.1

Since Nov 22Pushed 1y ago1 watchersCompare

[ Source](https://github.com/mohsenfathipour/captcha-generator)[ Packagist](https://packagist.org/packages/mohsenfathipour/captcha-generator)[ RSS](/packages/mohsenfathipour-captcha-generator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

Laravel CAPTCHA Generator
=========================

[](#laravel-captcha-generator)

A simple CAPTCHA generator for Laravel, designed to be easy to use and highly customizable. This package allows you to create CAPTCHA images with configurable width, height, background color, and characters. It also includes the option to generate dynamic and unique CAPTCHA images for multiple forms.

This package **supports Laravel 11** and provides a clean, lightweight solution for adding CAPTCHA to your forms.

Features
--------

[](#features)

- **Customizable Width and Height**: Set custom dimensions for the CAPTCHA image.
- **Background Color**: Choose any background color or use a random light color.
- **Contrasting Text Colors**: Text colors are automatically selected to contrast with the background.
- **Noise**: Add random lines for added difficulty.
- **No External Dependencies**: This package does not rely on external libraries or packages.

Installation
------------

[](#installation)

### 1. Install via Composer

[](#1-install-via-composer)

Add the package to your Laravel 11 project by running the following command:

```
composer require mohsenfathipour/captcha-generator
```

### 2. Publish the Configuration (Optional)

[](#2-publish-the-configuration-optional)

If you want to customize the CAPTCHA settings (like default width, height, or background color), you can publish the configuration file by running:

```
php artisan vendor:publish --provider="MohsenFathipour\CaptchaGenerator\CaptchaServiceProvider" --tag="config"
```

This will publish a `captcha.php` file to the `config` directory of your Laravel project.

Configuration
-------------

[](#configuration)

You can configure the default CAPTCHA options in the `config/captcha.php` file:

```
return [
    'width' => 120, // Default width of the CAPTCHA image
    'height' => 35, // Default height of the CAPTCHA image
    'characters' => 'ABCDEFGHJKLMNPQRTWZ234679', // Characters used in CAPTCHA (Avoids similar characters)
    'bg_color' => 'F0F0F0', // Default background color (hex format)
];
```

### Custom Background Color and Dimensions

[](#custom-background-color-and-dimensions)

If you want to use custom dimensions or background colors when generating CAPTCHA, you can pass the desired values as parameters to the route.

Usage
-----

[](#usage)

### 1. Generate CAPTCHA Image

[](#1-generate-captcha-image)

To generate the CAPTCHA image, simply access the following route:

```
GET /captcha/{name?}
```

Where:

- `{name?}` is an optional name for your form or CAPTCHA session. Each form can have its own CAPTCHA stored in the session.

### Example Usage in Blade Template

[](#example-usage-in-blade-template)

```

```

This will generate a CAPTCHA image for the form named `form1`.

### 2. Handle CAPTCHA Validation

[](#2-handle-captcha-validation)

In your form validation logic, you can validate the CAPTCHA input as follows:

```
use Illuminate\Support\Facades\Session;

$request->validate([
    'captcha' => function ($attribute, $value, $fail) {
        if ($value !== Session::get('captcha.form1')) {
            $fail('The captcha code is incorrect.');
        }
    },
]);
```

This code validates that the user-entered CAPTCHA matches the one stored in the session for `form1`.

Example Controller
------------------

[](#example-controller)

Here’s how you might use the CAPTCHA in your controller:

```
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Session;
use MohsenFathipour\CaptchaGenerator\Facades\Captcha;

class MyController extends Controller
{
    public function showCaptchaForm()
    {
        return view('myform');
    }

    public function validateCaptcha(Request $request)
    {
        $request->validate([
            'captcha' => function ($attribute, $value, $fail) {
                if ($value !== Session::get('captcha.form1')) {
                    $fail('The captcha code is incorrect.');
                }
            },
        ]);

        // Your form submission logic here...
    }
}
```

Customizing CAPTCHA Settings on the Fly
---------------------------------------

[](#customizing-captcha-settings-on-the-fly)

You can pass custom parameters like background color, width, and height directly in the URL:

```
GET /captcha/{name}?bgColor=FF5733&width=200&height=50
```

This will generate a CAPTCHA with a `#FF5733` background color, `200px` width, and `50px` height.

License
-------

[](#license)

This package is open source and available under the [MIT License](LICENSE).

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance40

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

533d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c36bb3bcd0b35ebdc362341420add06b4a99b8c4a3ee3b18e874bcb7776490f9?d=identicon)[mohsenfathipour](/maintainers/mohsenfathipour)

---

Top Contributors

[![mohsenfathipour](https://avatars.githubusercontent.com/u/32642574?v=4)](https://github.com/mohsenfathipour "mohsenfathipour (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mohsenfathipour-captcha-generator/health.svg)

```
[![Health](https://phpackages.com/badges/mohsenfathipour-captcha-generator/health.svg)](https://phpackages.com/packages/mohsenfathipour-captcha-generator)
```

###  Alternatives

[watson/active

Laravel helper for recognising the current route, controller and action

3253.6M14](/packages/watson-active)[spatie/laravel-pjax

A pjax middleware for Laravel 5

513371.8k11](/packages/spatie-laravel-pjax)[beyondcode/laravel-favicon

Create dynamic favicons based on your environment settings.

37345.5k](/packages/beyondcode-laravel-favicon)[glhd/conveyor-belt

14797.0k](/packages/glhd-conveyor-belt)[dragon-code/pretty-routes

Pretty Routes for Laravel

10058.7k4](/packages/dragon-code-pretty-routes)[erlandmuchasaj/laravel-gzip

Gzip your responses.

40129.3k2](/packages/erlandmuchasaj-laravel-gzip)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
