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

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

oh86/laravel-captcha
====================

captcha for app with laravel framework

v1.0.0(11mo ago)0362MITPHPPHP ^7.4 || ^8.0

Since Jun 13Pushed 11mo agoCompare

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

READMEChangelogDependencies (2)Versions (2)Used By (2)

验证码
===

[](#验证码)

### 一、配置 `config/captcha.php`

[](#一配置-configcaptchaphp)

```
return [
    'default' => env('CAPTCHA_DEFAULT_DRIVER', 'normalImage'),

    'normalImage' => [
        'characters' => ['2', '3', '4', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'm', 'n', 'p', 'q', 'r', 't', 'u', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'M', 'N', 'P', 'Q', 'R', 'T', 'U', 'X', 'Y', 'Z'],
        'length' => 4,          // 验证码长度
        'width' => 120,
        'height' => 36,
        'quality' => 90,
        'expire' => 600,        // 过期时间，单位为秒
        'sensitive' => false,   // 是否区分大小写
        'encrypt' => false,
        'lines' => 1,           // 干扰线数量
    ],

    'mathImage' => [
        'length' => 9,  // 数学式子长度，此处固定为9
        'width' => 120,
        'height' => 36,
        'quality' => 90,
        'math' => true,
        'expire' => 600,
    ],
];
```

### 二、使用

[](#二使用)

#### 1.获取验证码和验证验证码

[](#1获取验证码和验证验证码)

```
use Oh86\Captcha\Facades\Captcha;

// 获取
$captcha = Captcha::acquire();
$captcha = Captcha::driver('mathImage')->acquire();

// 验证
Captcha::verify(['key' => $captcha['key'], 'value' => 'abcd']);
Captcha::driver('mathImage')->verify(['key' => $captcha['key'], 'value' => '25']);
```

#### 2.验证验证码

[](#2验证验证码)

```
use App\Constants\ErrorCode;
use Illuminate\Http\Request;
use Oh86\Captcha\Facades\Captcha;
use Oh86\Http\Exceptions\ErrorCodeException;

trait CaptchaTrait
{
    /**
     * 校验验证码
     * @param \Illuminate\Http\Request $request
     * @throws \Oh86\Http\Exceptions\ErrorCodeException
     */
    protected function verifyCaptcha(Request $request)
    {
        $request->validate([
            'captcha_type' => 'nullable',
            'captcha' => 'required|array',
        ]);

        $captchaType = $request->captcha_type ?? Captcha::getDefaultDriver();
        $captcha = $request->captcha;

        if ($captchaType == 'normalImage' || $captchaType == 'mathImage'){
            $request->validate([
                'captcha.key' => 'required',
                'captcha.value' => 'required',
            ]);
        } elseif ($captchaType == 'tencentCloud') {
            $request->validate([
                'captcha.ticket' => 'required',
                'captcha.randStr' => 'required',
            ]);

            $captcha = ['userIp' => $request->ip()] + $captcha;
        } else {
            throw new ErrorCodeException(ErrorCode::Error, '验证码类型不支持');
        }

        // 本地环境不校验
        if (config('app.env') == 'local') {
            return;
        }

        if (!Captcha::driver($request->captcha_type)->verify($captcha)) {
            throw new ErrorCodeException(ErrorCode::Error, '验证码错误');
        }
    }
}
```

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance55

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity41

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

330d ago

### Community

Maintainers

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

---

Top Contributors

[![OneHundred86](https://avatars.githubusercontent.com/u/22148561?v=4)](https://github.com/OneHundred86 "OneHundred86 (9 commits)")

### Embed Badge

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

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

###  Alternatives

[webmozart/assert

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

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[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)
