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

ActivePackage

jason/captcha
=============

Laravel 10/11/12/13 Captcha Package

v1.1.0(1mo ago)04↑2900%MITPHPPHP ^8.2

Since Mar 24Pushed 1mo agoCompare

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

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

Captcha for Laravel 10/11/12/13
===============================

[](#captcha-for-laravel-10111213)

[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](https://packagist.org/packages/jason/captcha)[![PHP Version](https://camo.githubusercontent.com/d91d3d1139cf0d8faaa80eeeeac7d3c59c9319e56960ef81c948e4160be4c4c1/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e322d3737376262342e737667)](https://packagist.org/packages/jason/captcha)

一个为 Laravel 10/11/12/13 深度定制的现代化验证码组件。基于 [Intervention Image v3](https://image.intervention.io/v3) 构建，采用模块化设计，易于扩展和维护。

特性
--

[](#特性)

- **PHP 8.2+** 强类型支持。
- **Intervention Image v3**：使用最新的图像处理库，支持 GD 和 Imagick 驱动。
- **模块化架构**：解耦了验证码生成（Generators）、配置管理（Support）和图像绘制（ImageCreator）。
- **性能优化**：内置静态资源缓存，显著减少磁盘 I/O。
- **无状态 API 支持**：完美支持前后端分离项目。
- **高度可定制**：轻松定义多种验证码样式。

预览
--

[](#预览)

[![Preview Example](https://camo.githubusercontent.com/5796b984677c086025788097a4f9f89701595234cb98a23c7276c4ea5424c6ef/68747470733a2f2f696d6167652e6962622e636f2f6b5a784d4c6d2f696d6167652e706e67)](https://camo.githubusercontent.com/5796b984677c086025788097a4f9f89701595234cb98a23c7276c4ea5424c6ef/68747470733a2f2f696d6167652e6962622e636f2f6b5a784d4c6d2f696d6167652e706e67)

安装
--

[](#安装)

通过 Composer 安装：

```
composer require jason/captcha
```

在 Windows 环境下，确保 `php.ini` 中启用了 `php_gd.dll` 或 `php_imagick.dll`。

配置
--

[](#配置)

发布配置文件：

```
php artisan vendor:publish --provider="Jason\Captcha\CaptchaServiceProvider" --tag="config"
```

在 `config/captcha.php` 中，你可以定义多个验证码样式：

```
return [
    'default' => [
        'length' => 5,
        'width' => 120,
        'height' => 36,
        'quality' => 90,
        'math' => false,
        'expire' => 60,
    ],
    'math' => [
        'length' => 9,
        'width' => 120,
        'height' => 36,
        'math' => true,
    ],
    // ... 更多样式
];
```

使用方法
----

[](#使用方法)

### 1. 传统 Session 模式

[](#1-传统-session-模式)

在视图中显示验证码：

```

    @csrf

        {!! captcha_img() !!}

    提交

```

在控制器中进行验证：

```
public function store(Request $request)
{
    $request->validate([
        'captcha' => 'required|captcha',
    ]);

    // 验证通过后的逻辑...
}
```

### 2. 无状态 API 模式

[](#2-无状态-api-模式)

获取验证码数据（JSON 响应）： `GET /captcha/api/default`

返回示例：

```
{
    "sensitive": false,
    "key": "$2y$10$...",
    "img": "data:image/jpeg;base64,..."
}
```

前端验证时，需将 `key` 一并传回后端：

```
public function apiStore(Request $request)
{
    $request->validate([
        'captcha' => 'required|captcha_api:' . $request->input('key') . ',default',
    ]);

    // 验证通过后的逻辑...
}
```

辅助函数
----

[](#辅助函数)

- `captcha()`: 返回验证码图像响应。
- `captcha_src(string $style = 'default')`: 返回验证码图片的 URL 字符串。
- `captcha_img(string $style = 'default', array $attrs = [])`: 返回验证码图片的 HTML `` 标签。
- `captcha_check(string $value)`: 手动验证 Session 模式下的验证码。
- `captcha_api_check(string $value, string $key, string $style = 'default')`: 手动验证 API 模式下的验证码。

架构
--

[](#架构)

重构后的模块化设计：

- **[CaptchaGenerator](src/Contracts/CaptchaGenerator.php)**: 负责验证码内容的生成逻辑（字符串、算术等）。
- **[ImageCreator](src/Image/ImageCreator.php)**: 负责将生成的内容绘制成图像。
- **[Support/Config](src/Support/Config.php)**: 处理配置合并与默认值。
- **[Facades/Captcha](src/Facades/Captcha.php)**: 提供简洁的 Facade 访问接口。

鸣谢
--

[](#鸣谢)

本项目基于原 `mews/captcha` 进行现代化重构。

协议
--

[](#协议)

[MIT License](LICENSE)

###  Health Score

41

—

FairBetter than 88% of packages

Maintenance98

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity47

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

Total

2

Last Release

46d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

captchaLaravel Securitylaravel-captcha

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[bonecms/laravel-captcha

Captcha integration for Laravel

76138.4k](/packages/bonecms-laravel-captcha)[captcha-com/laravel-captcha

Laravel Captcha Package -- BotDetect PHP CAPTCHA generator integration for the Laravel framework.

38207.2k](/packages/captcha-com-laravel-captcha)[kompo/kompo

Laravel &amp; Vue.js FullStack Components for Rapid Application Development

11812.4k21](/packages/kompo-kompo)[anam/captcha

reCAPTCHA and invisible reCAPTCHA for Laravel. reCAPTCHA protects your app against spam and bot.

2843.4k](/packages/anam-captcha)[arcaptcha/arcaptcha-laravel

Laravel Package for the ArCaptcha

123.2k](/packages/arcaptcha-arcaptcha-laravel)

PHPackages © 2026

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