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

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

zaymedia/captcha
================

An easy to install self-hosted image captcha library implemented with PHP + InterventionImage.

1.0.1(2y ago)0177MITPHPPHP ^8.0

Since Sep 2Pushed 2y agoCompare

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

READMEChangelogDependencies (1)Versions (2)Used By (0)

Captcha
=======

[](#captcha)

Is an easy to install self-hosted image captcha library. Through a predefined dictionary, the library generates images that must be selected in a specific order.

This captcha solution may not be 100% secure against bots, but in combination with other popular captcha services, it will be an extra layer of security for your platform.

[![example](https://user-images.githubusercontent.com/35383529/220480833-dcd2b516-9b85-4944-8464-6a6f8d92fdb2.jpg)](https://user-images.githubusercontent.com/35383529/220480833-dcd2b516-9b85-4944-8464-6a6f8d92fdb2.jpg)

Contents
--------

[](#contents)

- [Installation](#installation)
- [Usage](#usage)
- [Cache Adapters](#cache-adapters)
- [Generate Links](#generate-links)
- [Validate Answer](#validate-answer)
- [Flush Links](#flush-links)
- [Customize Options](#customize-options)
- [License](#license)

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

[](#installation)

You can install the package via composer:

```
composer require zaymedia/captcha
```

Usage
-----

[](#usage)

To get started with the package, you must use the `make()` static method and pass as first parameter an identifier string. This identifier parameter will be used to store &amp; get the generated challenge and solution.

```
Use ZayMedia\Captcha\Captcha;
use ZayMedia\Captcha\CacheAdapters\SimpleFileCacheAdapter;

$captcha = Captcha::make('1', new SimpleFileCacheAdapter(__DIR__ . '/cache'));

var_dump($captcha->generateLinks());
```

> Generally you should use the user id, ip address, or a generated cookie.

Cache Adapters
--------------

[](#cache-adapters)

In order to use the Captcha class, you will need to choose a cache adapter so it can store the generated challenges somewhere. The package ships by default with the following adapters:

- `\ZayMedia\Captcha\CacheAdapters\LaravelCacheAdapter`
- `\ZayMedia\Captcha\CacheAdapters\SimpleFileCacheAdapter`

However, you can create and use your own adapter extending the abstract adapter class:

```
use ZayMedia\Captcha\CacheAdapters\AbstractCacheAdapter;

class MyCustomCacheAdapter extends AbstractCacheAdapter
{
    public function remember(string $key, int $expiresIn, callable $callback): mixed
    {
        //
    }

    public function get(string $key): mixed
    {
        //
    }

    public function forget(string $key): bool
    {
        //
    }
}
```

Generate Links
--------------

[](#generate-links)

You can generate / retrieve captcha links using the `generateLinks()` method. You can pass as first parameter the amount of links to generate. This method gets the generated links value from the cache, and generate if links are not found.

```
$links = $captcha->generateLinks(amount: 3);
```

Validate Answer
---------------

[](#validate-answer)

You can validate the user answer with the `validateAnswer()` method.

```
$captcha->validateAnswer($answer);
```

Flush Links
-----------

[](#flush-links)

You can flush the current cache value and force re-generate a new captcha challenge. *It's highly recommended to use this method when the user sends a wrong a answer.*

```
$captcha->flushLinks();
```

Customize Options
-----------------

[](#customize-options)

There are some few options that you can enable / disable when generating Captcha image.

```
// Enable or Disable image noise (Default: true)
$captcha->noise(value: false);

// Enable or Disable image background (Default: false)
$captcha->background(value: true);

// Enable or Disable dark theme (Default: false)
$captcha->darkTheme(value: true);
```

You can also customize the word universe. You can overwrite the word universe or merge your array with the default one.

```
$wordUniverse = [...];

$captcha->wordUniverse($wordUniverse);
// Or...
$captcha->mergeWordUniverse($wordUniverse);
```

License
-------

[](#license)

Captcha is open-sourced software licensed under the [MIT license](LICENSE).

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

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

988d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/12c6f72a02f5b02647391583cbae998a4baf4edc3eb917e816b460ac4f977a4f?d=identicon)[Zaytcevcom](/maintainers/Zaytcevcom)

---

Top Contributors

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

### Embed Badge

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

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

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)

PHPackages © 2026

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