PHPackages                             mydaniel/laravel-captcha - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. mydaniel/laravel-captcha

ActiveLaravel-package[Validation &amp; Sanitization](/categories/validation)

mydaniel/laravel-captcha
========================

A modern, highly customizable, and secure captcha package for Laravel.

v1.0.1(7mo ago)06MITPHPPHP ^8.0|^8.1|^8.2|^8.3|^8.4

Since Aug 20Pushed 7mo agoCompare

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

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

Laravel Captcha
===============

[](#laravel-captcha)

[![Latest Version on Packagist](https://camo.githubusercontent.com/1f21891dea8339fde2490010b264f82c86176f9b252d7e30bf79c1a6ffaf8300/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d7964616e69656c2f6c61726176656c2d636170746368612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mydaniel/laravel-captcha)[![Total Downloads](https://camo.githubusercontent.com/c11d5f3d03685e1943ac06ca5937bfa6746ca2a188a38ed83863e48b9e88b126/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d7964616e69656c2f6c61726176656c2d636170746368612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mydaniel/laravel-captcha)[![License](https://camo.githubusercontent.com/e45c75b4c66df65b6643a58152eeaf655f1de133d2e8aeac7ed2a9b9b56d7de0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d7964616e69656c2f6c61726176656c2d636170746368612e7376673f7374796c653d666c61742d737175617265)](https://github.com/daniyousefifar/laravel-captcha/blob/master/LICENSE)

A modern, highly customizable, and secure captcha package for Laravel.

This package provides an easy way to protect your web forms from bots by generating image-based captchas. It's designed to be both user-friendly for humans and challenging for bots.

Features
--------

[](#features)

- ✅ **SOLID Architecture:** Clean, maintainable, and easily extensible code.
- 🚀 **Multiple Generators:** Comes with `text` and `math` captcha generators out of the box.
- 🎨 **Highly Customizable:** Control everything from image dimensions and colors to character sets and distortion levels.
- 🛡️ **Secure:** Prevents replay attacks with one-time use keys and short expiration times.
- 🔌 **Seamless Laravel Integration:** Includes a Service Provider, Facade, and a custom Validation Rule for easy integration.
- 🌐 **Multi-language Support:** Validation messages can be easily translated.

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

[](#installation)

You can install the package via Composer:

```
composer require mydaniel/laravel-captcha
```

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

[](#configuration)

1. Publish the configuration and translation files using the following Artisan command:

    ```
    php artisan vendor:publish --provider="MyDaniel\Captcha\CaptchaServiceProvider"
    ```
2. This will create two new files:

    - `config/captcha.php`: Here you can configure all aspects of the captcha, including asset paths, character sets, and image settings for different profiles (`default`, `math`, etc.).
    - `lang/vendor/captcha/`: This directory will contain the translation files for validation messages.

Usage
-----

[](#usage)

Using the captcha involves two steps: displaying it in your form and validating the user's input.

### 1. Displaying the Captcha

[](#1-displaying-the-captcha)

In your Blade view, use the `Captcha::create()` facade to generate the captcha data.

```
{{-- Generate the captcha data --}}
@php
    $captcha = \MyDaniel\Captcha\Facades\Captcha::create('default'); // Or 'math', 'inverse', etc.
@endphp

    {{-- Display the captcha image --}}

    {{-- Input for the user to type the captcha code --}}

    {{-- Hidden field to store the captcha key --}}

@error('captcha_code')
    {{ $message }}
@enderror
```

### 2. Validating the Input

[](#2-validating-the-input)

In your controller or form request, use the provided `Captcha` validation rule.

#### Using the Validation Rule Object (Recommended)

[](#using-the-validation-rule-object-recommended)

This method is clean and type-safe.

```
use Illuminate\Http\Request;
use MyDaniel\Captcha\Rules\Captcha;

public function yourControllerMethod(Request $request)
{
    $request->validate([
        // ... other fields
        'captcha_code' => ['required', new Captcha($request->input('captcha_key'), 'default')],
        'captcha_key' => 'required|string',
    ]);

    // Captcha is valid, proceed...
}
```

#### Using the String-based Rule

[](#using-the-string-based-rule)

You can also use the rule as a string, which is useful in some scenarios.

```
use Illuminate\Http\Request;

public function yourControllerMethod(Request $request)
{
    $request->validate([
        // ... other fields
        'captcha_code' => 'required|captcha:' . $request->input('captcha_key') . ',default',
        'captcha_key' => 'required|string',
    ]);

    // Captcha is valid, proceed...
}
```

Customization
-------------

[](#customization)

### Custom Fonts and Backgrounds

[](#custom-fonts-and-backgrounds)

You can easily use your own fonts and background images.

1. Place your `.ttf` font files or `.png`/`.jpg` background images in any directory within your project (e.g., `public/assets/captcha`).
2. Update the `fonts_path` and `backgrounds_path` in your `config/captcha.php` file to point to these new directories.

### Creating a New Generator

[](#creating-a-new-generator)

The package is built to be extensible. To create a new captcha type (e.g., a question-based captcha):

1. Create a new class that implements the `\MyDaniel\Captcha\Contracts\CaptchaGeneratorContract` interface.
2. Implement the `generate(array $config): array` method.
3. Register your new generator in a service provider (e.g., `AppServiceProvider`):

    ```
    public function register()
    {
        $this->app->bind('captcha.generator.question', \App\Captcha\QuestionGenerator::class);
    }
    ```
4. You can now use `'driver' => 'question'` in a new profile in your `config/captcha.php` file.

Security
--------

[](#security)

- **One-Time Use Keys:** The package automatically invalidates a captcha key after the first validation attempt to prevent replay attacks.
- **Rate Limiting:** It is highly recommended to protect your forms with Laravel's built-in `throttle` middleware to prevent brute-force attacks.

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance66

Regular maintenance activity

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity54

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

Every ~35 days

Total

2

Last Release

227d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

laravelvalidationsecuritycaptchaform-protection

### Embed Badge

![Health badge](/badges/mydaniel-laravel-captcha/health.svg)

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

###  Alternatives

[proengsoft/laravel-jsvalidation

Validate forms transparently with Javascript reusing your Laravel Validation Rules, Messages, and FormRequest

1.1k2.3M49](/packages/proengsoft-laravel-jsvalidation)[olssonm/l5-zxcvbn

Implementation of the zxcvbn project by @dropbox for Laravel. Uses zxcvbn-php by @bjeavons.

28311.1k1](/packages/olssonm-l5-zxcvbn)[rebelinblue/laravel-zxcvbn

Service provider to use the zxcvbn project by @dropbox in Laravel 5.4 and above

1160.4k](/packages/rebelinblue-laravel-zxcvbn)

PHPackages © 2026

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