PHPackages                             hpd/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. hpd/captcha

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

hpd/captcha
===========

Laravel Captcha Code Package

v3.0.0(5mo ago)73.7k—0%MITPHPPHP ^7.4|^8.0

Since Dec 8Pushed 4mo ago1 watchersCompare

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

READMEChangelog (4)Dependencies (1)Versions (5)Used By (0)

Captcha for Laravel
===================

[](#captcha-for-laravel)

*A Lightweight CAPTCHA Solution for Laravel*

Maintained by [Hamid HpD](https://github.com/hamid-hpd)

Preview
-------

[](#preview)

[![Preview](./docs/images/preview.png)](./docs/images/preview.png)

Table of Contents
-----------------

[](#table-of-contents)

- [Introduction](#introduction)

    - [Features](#features)
- [Installation](#installation)
- [Usage](#usage)
- [Configuration](#configuration)

    - [Properties](#properties)
- [How to use](#how-to-use)

    - [Session mode](#session-mode)
        - [Example](#example)
    - [API mode](#api-mode)
        - [Example](#example-1)
- [What's New](#whats-new)

    - [Version 3.0.0](#version-300)
    - [Changelog](#changelog)
- [License](#license)
- [Other Proiects](#check-out-my-other-projects)

Introduction
------------

[](#introduction)

🛡️ HPD Captcha — Simple, Secure &amp; Laravel Friendly

- A lightweight, privacy-friendly CAPTCHA package for Laravel — no external services, no API keys, no tracking.

### ✨ Features

[](#-features)

✅ Works fully offline (no external API)

✅ Simple image-based CAPTCHA

✅ Easy integration with Laravel forms

✅ Supports Laravel 8.x → 12.x

✅ Customizable appearance &amp; difficulty

✅ No tracking, no cookies, no external requests

✅ Lightweight &amp; fast

---

⚠️ Important Notice
-------------------

[](#️-important-notice)

> **Version 1.x of HPD Captcha is officially deprecated.**
> All new projects should use **v3.x**.
> Upgrading from v1/v2? Check the [Upgrade Guide](./UPGRADE.md).

---

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

[](#installation)

Require this package with composer:

```
composer require hpd/captcha

```

Usage
-----

[](#usage)

It doesn't need to add CaptchaServiceProvider to the providers array in config/app.php.

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

[](#configuration)

To use your own settings, first publish the config file:

```
php artisan vendor:publish --tag=hpd-captcha-config
```

Then customize configuration properties as you like.

```
return [
    'disable' => env('CAPTCHA_DISABLE', env('APP_ENV') !== 'production'),
    'characters' => [
        'lowercase' => 'abdefghjklmnpqrstuvwxyz',
        'uppercase' => 'ABCDEFGHJKLMNPQRSTUVWXYZ',
        'digits' => '23456789' //
    ],
    'default' => [
        'length' => 5,
        'bgColor' => '#FFFFFF',
        'color' => 'multi',
        'noiseLines' => true,
        'noise' => true,
        'noiseColor' => '#FFFFFF',
        'sensitive' => false,
        'digits' => true,
        'uppercase' => true,
        'lowercase' => true,
        'alpha' => 10,
        'blur' => true,
    ],
    ...
];
```

### Optional Words File Publishing (version &gt;=3.0.)

[](#optional-words-file-publishing-version-30)

The package comes with a built-in words file (resources/data/words\_en.php) used for CAPTCHA generation, so it works immediately without any setup.

If you want to customize the words list, you can publish it to your application:

```
php artisan vendor:publish --tag=hpd-captcha-words
```

### Properties

[](#properties)

The following properties are customizable from published config.php file.

```
protected $config;
    protected string $bgColor = "#000000";//'random'
    protected string $color = "#FFFFFF";  //'random','multi'
    protected string $noiseColor = "#FFFFFF";//'random'
    protected bool $blur = false;
    protected int $alpha = 0; // 0 -> 1
    protected bool $noise = false;
    protected string $noiseMode = 'cross';//'vertical','horizontal','cross','random'
    protected float $noiseDensity = 0.1; // 0 -> 1.0
    protected float $noiseIntensity = 1.0; // 0 -> 1.0
    protected bool $noiseLines = false;
    protected bool $difficulty = false;
    protected int $length = 5;
    protected int $expire = 60;
    protected bool $sensitive = false;
    protected array $characters;
    protected bool $lowercase = true;
    protected bool $uppercase = false;
    protected bool $digits = false;
    protected string $fontDir = '';
    protected string $font = 'libre.ttf';
    protected int $fontSize = 24;
    protected string $type = 'string';
```

How to use
----------

[](#how-to-use)

### Session mode

[](#session-mode)

Session mode is designed for traditional web forms. The captcha solution is stored in the server-side session and validated against the user’s input when the form is submitted

You can use the following helper functions in your project to get a Captcha image.

```
    captcha(); // returns image

    captcha_get_src()// returns image source(URl)

    captcha_get_html()// returns img html element
```

Pass the configuration name to the function. If omitted, the 'default' configuration is

```
    captcha('default'); // returns image

    captcha_get_src('easy')// returns image source(URl)

    captcha_get_img('dark')// returns img element
```

#### Example

[](#example)

Get Captcha image src:

```

```

Get img element:

```
     {{!! captcha_get_img()!!}}
```

Validation

```
    Route::post('captcha_check', function() {
         $validator = Validator::make($request->all(), [
                'captcha' => 'required|captcha',
            ]);

            if ($validator->fails()) {
                return redirect()->back()
                    ->withErrors($validator)
                    ->withInput();
            }

 });
```

### API mode

[](#api-mode)

API mode is designed for single-page applications (SPA), mobile apps, or any frontend that communicates with the backend through JSON APIs. Instead of sessions, the captcha state is temporarily stored in the cache. A captcha\_token is returned and must be included in subsequent requests.

```
     [
        'token'=>'816fc4e459eb3bd240a58beee41e723df2d1b1f29300f2a7920cdc372f728695'
        ,
        'image'=>'data:image/png;base64,'.$this->createBase64FromImg($this->image)
     ]
```

#### Example

[](#example-1)

```
        async function loadCaptcha(config='default') {
        try {
        const response = await fetch(`hpd/captcha/api/${config}`);
        const data = await response.json();

        const img = document.createElement("img");
        img.src = data.image;
        document.getElementById("captcha-container").appendChild(img);
        document.getElementById('captcha_token').value = data.token;

    } catch (error) {
        console.error('CAPTCHA loading failed:', error);
    }
}

// Call the function
loadCaptcha('math');
```

Validation

```
    $validator = validator()->make(request()->all(),
        ['captcha' => 'required|captcha_api:'. request('captcha_token')

        ];
    );
    if ($validator->fails()) {
        return response()->json([
            'captcha' => 'Invalid captcha',
        ],422);

    } else {
        // continue
    }
```

What's New
----------

[](#whats-new)

### Version 3.0.0

[](#version-300)

- **Added `word_puzzle` type configuration option**

    Now you can generate captcha challenges using incomplete English words from a dictionary. Users see a word with missing letters (e.g., ap\_le) and must type the complete word (apple).

    ```
     {!!captcha_get_img('word_puzzle_default')!!}
    ```
- **From now on, the `color` property in all types supports the `multi` option.**
- **⚠️ Updated Routes with `hpd` Prefix**

    All captcha routes have been updated to include a hpd prefix for better organization and avoiding naming conflicts with other CAPTCHA packages.

    - Web routes now use: ```
        hpd/captcha/{config?}

        ```
    - API routes now use: ```
        hpd/captcha/api/{config?}
        ```
- **All published config files use the `hpd_` prefix to:**

    - **Avoid conflicts** with other CAPTCHA packages
    - **Unique identification** for HPD Captcha package
    - **Easy management** in projects with multiple packages

    Package FilePublished AsPurpose`config.php``hpd_captcha.php`Main CAPTCHA settings &amp; themes
- **All data files, such as the words file, will be placed in the address `storage\hpd\captcha\words_en.php` after publishing.**
- **Smart detection of published vs. package config and data files with seamless fallback.**
- **Refactored package directories structure**

### Changelog

[](#changelog)

Checkout the [CHANGELOG](./CHANGELOG.md) for details on updates.

License
-------

[](#license)

This project is licensed under the [MIT License](./LICENSE).

Check Out My Other Projects
---------------------------

[](#check-out-my-other-projects)

Hey! If you liked this package, you might enjoy some of my other work too:

- [Validatify](https://github.com/hamid-hpd/validatify.git) – A PHP input validation library.

I'm always building and sharing new stuff — feel free to take a look, star ⭐ what you like, or even open a PR!

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance75

Regular maintenance activity

Popularity26

Limited adoption so far

Community7

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 ~368 days

Total

4

Last Release

152d ago

Major Versions

v1.0.1 → v2.0.02025-08-29

v2.0.0 → v3.0.02025-12-18

### Community

Maintainers

![](https://www.gravatar.com/avatar/374b7367a676ad9b6d883e2eb4189b22629a43385655f3b7598fbfb1e76894f8?d=identicon)[hamid\_hpd](/maintainers/hamid_hpd)

---

Top Contributors

[![hamid-hpd](https://avatars.githubusercontent.com/u/68687554?v=4)](https://github.com/hamid-hpd "hamid-hpd (16 commits)")

### Embed Badge

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

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

###  Alternatives

[spatie/laravel-honeypot

Preventing spam submitted through forms

1.6k6.0M60](/packages/spatie-laravel-honeypot)[proengsoft/laravel-jsvalidation

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

1.1k2.3M49](/packages/proengsoft-laravel-jsvalidation)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[axlon/laravel-postal-code-validation

Worldwide postal code validation for Laravel and Lumen

3853.3M1](/packages/axlon-laravel-postal-code-validation)[sunspikes/clamav-validator

Custom Laravel 5 anti-virus validator for file uploads.

3651.8M3](/packages/sunspikes-clamav-validator)[laravel-validation-rules/credit-card

Validate credit card number, expiration date, cvc

2412.2M5](/packages/laravel-validation-rules-credit-card)

PHPackages © 2026

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