PHPackages                             mortezaashrafi/filament-shield-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. mortezaashrafi/filament-shield-captcha

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

mortezaashrafi/filament-shield-captcha
======================================

Production-grade inline image CAPTCHA field for Filament forms (PHP GD, zero image persistence).

v1.0.1(1mo ago)6233↑461.1%2MITPHPPHP ^8.2 || ^8.3 || ^8.4 || ^8.5

Since May 25Pushed 1mo agoCompare

[ Source](https://github.com/mortezaashrafi/filament-shield-captcha)[ Packagist](https://packagist.org/packages/mortezaashrafi/filament-shield-captcha)[ RSS](/packages/mortezaashrafi-filament-shield-captcha/feed)WikiDiscussions main Synced 1w ago

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

mortezaashrafi/filament-shield-captcha
======================================

[](#mortezaashrafifilament-shield-captcha)

A production-grade inline Image CAPTCHA field for Filament forms.

- Native **PHP GD** only (no Intervention Image)
- **Zero image file persistence** (no temporary files, nothing written to disk)
- Base64 **data URI** output rendered inline inside Filament forms
- Deterministic noise per challenge (stable across Livewire re-renders)
- Session/cache-based server-side verification with TTL, max attempts, replay protection
- Bundled fonts (OFL): Vazirmatn + Noto Sans, with custom font path support
- **Auto RTL support**: Automatically switches fonts based on locale direction.

Screenshots
-----------

[](#screenshots)

Panel (Light / Dark):

  [![Filament panel CAPTCHA (Light)](https://camo.githubusercontent.com/caecdf6be0e4e06af71edf490d0310874a5e5a910aa31a9e7613a90ac3ee2cc8/68747470733a2f2f6d6f7274657a61617368726166692e636f6d2f73746f726167652f736372697074732f736869656c642d636170746368612f66696c616d656e742f70616e656c2d6c6974652e6a7067)](https://camo.githubusercontent.com/caecdf6be0e4e06af71edf490d0310874a5e5a910aa31a9e7613a90ac3ee2cc8/68747470733a2f2f6d6f7274657a61617368726166692e636f6d2f73746f726167652f736372697074732f736869656c642d636170746368612f66696c616d656e742f70616e656c2d6c6974652e6a7067) [![Filament panel CAPTCHA (Dark)](https://camo.githubusercontent.com/f4434883253227076282d7f90e5b510d08094656f1bc51562b64467e4f2024b8/68747470733a2f2f6d6f7274657a61617368726166692e636f6d2f73746f726167652f736372697074732f736869656c642d636170746368612f66696c616d656e742f70616e656c2d6461726b2e6a7067)](https://camo.githubusercontent.com/f4434883253227076282d7f90e5b510d08094656f1bc51562b64467e4f2024b8/68747470733a2f2f6d6f7274657a61617368726166692e636f6d2f73746f726167652f736372697074732f736869656c642d636170746368612f66696c616d656e742f70616e656c2d6461726b2e6a7067) Login page (Light / Dark):

  [![Filament login CAPTCHA (Light)](https://camo.githubusercontent.com/69aafc05ddc3a212712bde75942aa55412e35fad8318a7546494ccb1c1bfd0b0/68747470733a2f2f6d6f7274657a61617368726166692e636f6d2f73746f726167652f736372697074732f736869656c642d636170746368612f66696c616d656e742f6c6f67696e2d6c6974652e6a7067)](https://camo.githubusercontent.com/69aafc05ddc3a212712bde75942aa55412e35fad8318a7546494ccb1c1bfd0b0/68747470733a2f2f6d6f7274657a61617368726166692e636f6d2f73746f726167652f736372697074732f736869656c642d636170746368612f66696c616d656e742f6c6f67696e2d6c6974652e6a7067) [![Filament login CAPTCHA (Dark)](https://camo.githubusercontent.com/de352829f0fa7742520612c6a9527acb25e88693ddc56de7497f552b51ecfbca/68747470733a2f2f6d6f7274657a61617368726166692e636f6d2f73746f726167652f736372697074732f736869656c642d636170746368612f66696c616d656e742f6c6f67696e2d6461726b2e6a7067)](https://camo.githubusercontent.com/de352829f0fa7742520612c6a9527acb25e88693ddc56de7497f552b51ecfbca/68747470733a2f2f6d6f7274657a61617368726166692e636f6d2f73746f726167652f736372697074732f736869656c642d636170746368612f66696c616d656e742f6c6f67696e2d6461726b2e6a7067) Compatibility
-------------

[](#compatibility)

PackageVersionsPHP8.2, 8.3, 8.4, 8.5Laravel11, 12, 13Filament3, 4, 5Installation
------------

[](#installation)

```
composer require mortezaashrafi/filament-shield-captcha
```

### GD requirement

[](#gd-requirement)

This package requires PHP GD with FreeType support (for `imagettftext()`).

Common installs:

- Debian/Ubuntu: `sudo apt-get install php-gd`
- Alpine: `apk add php82-gd` (match your PHP version)

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

[](#configuration)

Publish the config file:

```
php artisan vendor:publish --tag=filament-shield-captcha-config
```

Config file: `config/filament-shield-captcha.php`

Usage in Forms
--------------

[](#usage-in-forms)

```
use MortezaAshrafi\FilamentShieldCaptcha\Forms\Components\Captcha;

Captcha::make('captcha')
    ->required()
```

Customization (Fluent API)
--------------------------

[](#customization-fluent-api)

MethodDescriptionRange / Limits`->length(int)`Number of characters in CAPTCHA1 to 12 (recommended 4-6)`->width(int)`Image width in pixelsmin 100 (recommended 220)`->height(int)`Image height in pixelsmin 30 (recommended 60)`->fontSize(int)`Font size in pixels12 to 40 (recommended 26)`->font(string)`Use bundled font key (`vazirmatn`, `noto_sans`)-`->rtl()`Force RTL mode (uses `rtl` font from config)-`->ltr()`Force LTR mode (uses `ltr` font from config)-`->numeric()`Numbers only (0-9)-`->alphabetic()`Letters only (A-Z)-`->alphanumeric()`Letters and numbers (Default)-`->symbols(string)`Alphanumeric + custom symbolsdefault symbols: `!@#$%^&*+-=``->charset(string)`Completely custom character set-`->caseSensitive(bool)`Require exact case matchingdefault: `false``->noise(level, lines, dots)`Adjust image noise complexitylevel 0-5 (default 2)`->ttl(int)`Challenge expiry in secondsdefault 300`->maxAttempts(int)`Max wrong attempts before lockdefault 5Example with full options:

```
Captcha::make('captcha')
    ->width(220)
    ->height(60)
    ->length(5)
    ->fontSize(26)
    ->font('vazirmatn')
    ->lightColors(background: [255, 255, 255], text: [30, 30, 30])
    ->darkColors(background: [24, 24, 27], text: [245, 245, 245])
    ->alphanumeric()
    ->caseSensitive(false)
    ->noise(level: 2, lines: 3, dots: 40)
    ->ttl(300)
    ->maxAttempts(5)
```

Integration with Filament Auth Pages
------------------------------------

[](#integration-with-filament-auth-pages)

To add CAPTCHA to Filament's built-in Login, Register, or Reset Password pages (v5), follow these steps:

### 1. Create Custom Auth Components

[](#1-create-custom-auth-components)

Extend the original Filament Auth pages and use the `InteractsWithCaptcha` trait.

**Login Page:** `app/Filament/Pages/Auth/Login.php`

```
namespace App\Filament\Pages\Auth;

use Filament\Schemas\Schema;
use Filament\Auth\Pages\Login as BaseLogin;
use MortezaAshrafi\FilamentShieldCaptcha\Concerns\InteractsWithCaptcha;

class Login extends BaseLogin
{
    use InteractsWithCaptcha;

    public function form(Schema $form): Schema
    {
        return parent::form($form)
            ->components([
                ...$form->getComponents(),
                $this->getCaptchaFormComponent()
                ->width(371),
            ]);
    }
}
```

**Register Page:** `app/Filament/Pages/Auth/Register.php`

```
namespace App\Filament\Pages\Auth;

use Filament\Schemas\Schema;
use Filament\Auth\Pages\Register as BaseRegister;
use MortezaAshrafi\FilamentShieldCaptcha\Concerns\InteractsWithCaptcha;

class Register extends BaseRegister
{
    use InteractsWithCaptcha;

    public function form(Schema $form): Schema
    {
        return parent::form($form)
            ->components([
                ...$form->getComponents(),
                $this->getCaptchaFormComponent()
                ->width(371),
            ]);
    }
}
```

**Password Reset Page:** `app/Filament/Pages/Auth/RequestPasswordReset.php`

```
namespace App\Filament\Pages\Auth;

use Filament\Schemas\Schema;
use Filament\Auth\Pages\RequestPasswordReset as BaseRequestPasswordReset;
use MortezaAshrafi\FilamentShieldCaptcha\Concerns\InteractsWithCaptcha;

class Register extends BaseRequestPasswordReset
{
    use InteractsWithCaptcha;

    public function form(Schema $form): Schema
    {
        return parent::form($form)
            ->components([
                ...$form->getComponents(),
                $this->getCaptchaFormComponent()
                ->width(371),
            ]);
    }
}
```

### 2. Register Custom Pages in Panel Provider

[](#2-register-custom-pages-in-panel-provider)

Update your `AdminPanelProvider.php` (or other panel provider) to use your custom Auth pages:

```
// app/Providers/Filament/AdminPanelProvider.php

public function panel(Panel $panel): Panel
{
    return $panel
        ->login(\App\Filament\Pages\Auth\Login::class)
        ->registration(\App\Filament\Pages\Auth\Register::class)
        ->passwordReset(\App\Filament\Pages\Auth\RequestPasswordReset::class)
        // ...
}
```

RTL / LTR Support
-----------------

[](#rtl--ltr-support)

The package automatically detects the current locale direction. You can configure default fonts for each direction in the config file:

```
'fonts' => [
    'rtl' => 'vazirmatn',
    'ltr' => 'noto_sans',
],
```

Security &amp; Architecture
---------------------------

[](#security--architecture)

- **In-Memory Generation**: Images are created via GD and encoded to base64 data URIs. No files are ever written to the disk.
- **Server-Side Verification**: The expected answer is never exposed to the client.
- **Replay Protection**: Successful verification invalidates the challenge immediately.
- **Rate Limiting**: Wrong attempts increment a counter; once `maxAttempts` is reached, the challenge is locked and must be refreshed.

Fonts
-----

[](#fonts)

Bundled (OFL):

- **Vazirmatn**: Excellent for Persian/Arabic-friendly UI.
- **Noto Sans**: Reliable Latin-friendly default.

To use your own font:

```
Captcha::make('captcha')->fontPath(storage_path('fonts/my-font.ttf'));
```

Testing
-------

[](#testing)

```
composer test      # Runs PHPUnit suite
composer analyse   # Runs PHPStan static analysis
composer format    # Runs Laravel Pint formatter
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

47

—

FairBetter than 93% of packages

Maintenance90

Actively maintained with recent releases

Popularity23

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 87.5% 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 ~5 days

Total

2

Last Release

54d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/85690690?v=4)[Morteza Ashrafi](/maintainers/mortezaashrafi)[@mortezaashrafi](https://github.com/mortezaashrafi)

---

Top Contributors

[![mortezaashrafi](https://avatars.githubusercontent.com/u/85690690?v=4)](https://github.com/mortezaashrafi "mortezaashrafi (7 commits)")[![Hamoi1](https://avatars.githubusercontent.com/u/92602172?v=4)](https://github.com/Hamoi1 "Hamoi1 (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mortezaashrafi-filament-shield-captcha/health.svg)

```
[![Health](https://phpackages.com/badges/mortezaashrafi-filament-shield-captcha/health.svg)](https://phpackages.com/packages/mortezaashrafi-filament-shield-captcha)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.3M347](/packages/psalm-plugin-laravel)[propaganistas/laravel-disposable-email

Disposable email validator

6023.0M7](/packages/propaganistas-laravel-disposable-email)[harris21/laravel-fuse

Circuit breaker for Laravel queue jobs. Protect your workers from cascading failures.

45955.7k](/packages/harris21-laravel-fuse)[illuminate/pipeline

The Illuminate Pipeline package.

9349.2M291](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10534.1M1.1k](/packages/illuminate-pagination)[illuminate/redis

The Illuminate Redis package.

8314.6M388](/packages/illuminate-redis)

PHPackages © 2026

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