PHPackages                             zhang-mason/laravel-captcha-kit - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. zhang-mason/laravel-captcha-kit

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

zhang-mason/laravel-captcha-kit
===============================

Unified captcha verification for Laravel — Google reCAPTCHA v2/v3, hCaptcha, and Cloudflare Turnstile behind one Manager-based API.

v1.0.3(3w ago)118↓50%MITPHPPHP ^8.2CI passing

Since Jul 10Pushed 1mo agoCompare

[ Source](https://github.com/Zhang-mason/laravel-captcha-kit)[ Packagist](https://packagist.org/packages/zhang-mason/laravel-captcha-kit)[ RSS](/packages/zhang-mason-laravel-captcha-kit/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (13)Versions (7)Used By (0)

mason/captcha
=============

[](#masoncaptcha)

Unified captcha verification for Laravel. One Manager-based API in front of Google reCAPTCHA v2 (checkbox and invisible), reCAPTCHA v3, hCaptcha, and Cloudflare Turnstile — switch providers by changing config, not code.

> **Status**: reCAPTCHA v2 is fully supported (backend verification, validation rule, middleware, and the `` widget). Backend verification for reCAPTCHA v3, hCaptcha, and Turnstile is implemented; their frontend widgets are coming in a later release.

Requirements
------------

[](#requirements)

- PHP 8.2+ (Laravel 13 requires PHP 8.3+)
- Laravel 12 / 13

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

[](#installation)

```
composer require zhang-mason/laravel-captcha-kit
```

Publish the config file if you need to customise it:

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

Set your keys in `.env`:

```
CAPTCHA_DRIVER=recaptcha_v2
RECAPTCHA_V2_SITE_KEY=your-site-key
RECAPTCHA_V2_SECRET_KEY=your-secret-key
RECAPTCHA_V2_MODE=checkbox # or: invisible
```

Usage
-----

[](#usage)

### Frontend

[](#frontend)

Render the widget inside your form. The script tag is included automatically and deduplicated across multiple widgets.

```

    @csrf

    Send

```

In `invisible` mode the widget binds to its surrounding form (or pass `form="form-id"`) and submits automatically once the challenge completes.

### Validation rule

[](#validation-rule)

```
use Mason\Captcha\Rules\CaptchaRule;

public function rules(): array
{
    return [
        'g-recaptcha-response' => ['required', new CaptchaRule],
        // Target a specific driver:
        'cf-turnstile-response' => ['required', CaptchaRule::driver('turnstile')],
        // reCAPTCHA v3 with an expected action:
        'g-recaptcha-response' => ['required', CaptchaRule::driver('recaptcha_v3')->action('login')],
    ];
}
```

### Middleware

[](#middleware)

```
Route::post('/contact', ContactController::class)->middleware('captcha');
Route::post('/login', LoginController::class)->middleware('captcha:recaptcha_v3,login');
```

Failed verifications throw a `ValidationException` (HTTP 422 for JSON requests, redirect back with errors otherwise).

### Facade

[](#facade)

```
use Mason\Captcha\Facades\Captcha;

$result = Captcha::verify($request->input('g-recaptcha-response'), $request->ip());

if ($result->failed()) {
    abort(422);
}

// A specific driver:
$result = Captcha::driver('turnstile')->verify($token, $ip);

// reCAPTCHA v3 exposes the score:
$result = Captcha::driver('recaptcha_v3')->verify($token, $ip);
$result->score;    // e.g. 0.9
$result->passed(); // success AND score >= configured threshold
```

`verify()` returns a `VerificationResult` with `success`, `score`, `action`, `hostname`, `challengedAt`, `errorCodes`, and the `raw` provider response. Use `passed()` / `failed()` — they also apply the v3 score threshold.

### Custom drivers

[](#custom-drivers)

```
use Mason\Captcha\Facades\Captcha;

Captcha::extend('my_provider', fn ($app) => new MyProviderDriver(/* ... */));
```

### Testing

[](#testing)

```
use Mason\Captcha\Facades\Captcha;

public function test_contact_form(): void
{
    Captcha::fake(); // every verification passes, no HTTP

    $this->post('/contact', [/* ... */])->assertOk();

    Captcha::fake()->assertVerified();
}

Captcha::fake()->failing();     // every verification fails
Captcha::fake()->scoring(0.3);  // simulate a v3 score
```

You can also skip verification entirely per environment via `captcha.skip_environments` (defaults to `['testing']`).

Configuration notes
-------------------

[](#configuration-notes)

- **Fail-closed by default**: if the provider's siteverify endpoint is unreachable, verification fails. Set `CAPTCHA_ON_FAILURE=pass` to fail open instead.
- reCAPTCHA v2 checkbox vs. invisible is a frontend-only difference — both use the same driver; switch with `RECAPTCHA_V2_MODE`.

Development
-----------

[](#development)

```
composer install
composer test  # pest
composer lint  # pint
```

License
-------

[](#license)

MIT

###  Health Score

43

—

FairBetter than 89% of packages

Maintenance94

Actively maintained with recent releases

Popularity11

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

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

Total

4

Last Release

24d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/207661830?v=4)[Zhang-mason](/maintainers/Zhang-mason)[@Zhang-mason](https://github.com/Zhang-mason)

---

Top Contributors

[![Zhang-mason](https://avatars.githubusercontent.com/u/207661830?v=4)](https://github.com/Zhang-mason "Zhang-mason (14 commits)")

---

Tags

laravelrecaptchacaptchaturnstilehcaptcha

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/zhang-mason-laravel-captcha-kit/health.svg)

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.4M354](/packages/psalm-plugin-laravel)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

80427.1M249](/packages/laravel-mcp)[laravel/socialite

Laravel wrapper around OAuth 1 &amp; OAuth 2 libraries.

5.7k113.1M1.0k](/packages/laravel-socialite)[illuminate/auth

The Illuminate Auth package.

9328.5M1.4k](/packages/illuminate-auth)[api-platform/laravel

API Platform support for Laravel

58190.1k21](/packages/api-platform-laravel)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

818355.4k3](/packages/defstudio-telegraph)

PHPackages © 2026

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