PHPackages                             canon1014/captcha-lumen - 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. [Security](/categories/security)
4. /
5. canon1014/captcha-lumen

ActiveLibrary[Security](/categories/security)

canon1014/captcha-lumen
=======================

captcha for lumen

2.0(7y ago)0175MITPHPPHP &gt;=5.4

Since Jul 2Pushed 7y agoCompare

[ Source](https://github.com/canon1014/captcha-Lumen5.7)[ Packagist](https://packagist.org/packages/canon1014/captcha-lumen)[ RSS](/packages/canon1014-captcha-lumen/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (5)Versions (3)Used By (0)

Captcha for Lumen 5.7
=====================

[](#captcha-for-lumen-57)

本项目修改自[Captcha for Laravel 5](https://github.com/mewebstudio/captcha) 和 [lumen-captcha](https://github.com/Yangbx/captcha-lumen)

Requirement
-----------

[](#requirement)

Lumen version &gt;= v5.5

Preview
-------

[](#preview)

[![Preview](https://camo.githubusercontent.com/e5ebfe735c8c3845df743219a60cb26c43754c66b6547dce56f8e82c64e8b261/687474703a2f2f692e696d6775722e636f6d2f485974723734342e706e67)](https://camo.githubusercontent.com/e5ebfe735c8c3845df743219a60cb26c43754c66b6547dce56f8e82c64e8b261/687474703a2f2f692e696d6775722e636f6d2f485974723734342e706e67)

Install
-------

[](#install)

- 此 Package 必须开启 Redis才能使用，因为验证码与绑定验证码的 uuid 都是保存在Redis的。

```
composer require canon/captcha-lumen

```

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

[](#how-to-use)

在`bootstrap/app.php`中注册Captcha Service Provider：

```
    $app->register(Canon\CaptchaLumen\CaptchaServiceProvider::class);
    class_alias('Canon\CaptchaLumen\Facades\Captcha','Captcha');
```

Set
---

[](#set)

在`bootstrap/app.php`中可以设定各种自定义类型的验证码属性，更多详细设定请查看 [Captcha for Laravel 5](https://github.com/mewebstudio/captcha)

```
/**
 * captcha set
 */
config(['captcha'=>
    [
        'useful_time' => 5, //验证码有效时间（分钟）
        'captcha_characters' => '2346789abcdefghjmnpqrtuxyzABCDEFGHJMNPQRTUXYZ',
        'sensitive' => false, //验证码是否判断大小写
        'login'   => [ //验证码样式
            'length'    => 4, //验证码字数
            'width'     => 120, //图片宽度
            'height'    => 36, //字体大小和图片高度
            'angle'     => 10, //字体倾斜度
            'lines'     => 2, //横线数
            'quality'   => 90, //品质
            'invert'    =>false, //反相
            'bgImage'   =>true, //背景图
            'bgColor'   =>'#ffffff',
            'fontColors'=>['#339900','#ff3300','#9966ff','#3333ff'],//字体颜色
        ],
    ]
]);
```

如果不配置设定档，默认就是default，验证码有效时限为5分钟。

Example
-------

[](#example)

因为 Lumen 都是无状态的 API，所以验证码图片都会绑上一个 UUID，先获得验证码的 UUID 跟图片的 URL，�验证时再一併发送验证码与 UUID。

### Generate

[](#generate)

获得验证码：

```
{Domain}/captchaInfo/{type?}

```

`type`就是在 config 中定义的 Type，如果不指定`type`，默认为`default`样式，Response：

```
{
  "captchaUrl": "http://{Domain}/captcha/default/782fdc90-3406-f2a9-9573-444ea3dc4d5c",
  "captchaUuid": "782fdc90-3406-f2a9-9573-444ea3dc4d5c"
}
```

`captchaUrl`为验证码图片的 URL，`captchaUuid`为绑定验证码图片的uuid。

#### validate

[](#validate)

在发送 Request 时将验证码与 UUID 一併送回 Server 端，在接收参数时做验证即可：

```
# 原版验证
# 因为我修改了存储位置也没有使用该方法作为验证所以已失效,未来将会修改
public function checkCaptcha(Request $request, $type = 'default',$captchaUuid)
{
    $this->validate($request,[
        'captcha'=>'required|captcha:'.$captchaUuid
    ]);
    ...
}

# 我现在使用的
public function checkCaptchaCode($captchaId,$userCode)
{
    $captchaId = 'captcha_'.$captchaId;
    $redis = app('redis.connection');
    $captchaCode = $redis->get($captchaId);

    if(empty($captchaCode)){
        return $apidoc->loginCaptchaError();
    }

    $sensitive = config('captcha.sensitive');
    if (!$sensitive){
        $captchaCode = strtolower($captchaCode);
        $userCode = strtolower($userCode);
    }

    if($captchaCode == $userCode){
        return $apidoc->loginCaptchaSuccess();
    }

    return $apidoc->loginCaptchaError();
}
```

Update log
----------

[](#update-log)

- v1.0 （2019-07）
    - 验证码图片的显示错误问题
    - 验证码存储位置由Cache=&gt;Redis
    - 部分配置文件不生效
    - 原版验证修改（计划）

Links
-----

[](#links)

- [Intervention Image](https://github.com/Intervention/image)
- [L5 Captcha on Github](https://github.com/mewebstudio/captcha)
- [L5 Captcha on Packagist](https://packagist.org/packages/mews/captcha)
- [For L4 on Github](https://github.com/mewebstudio/captcha/tree/master-l4)
- [License](http://www.opensource.org/licenses/mit-license.php)
- [Laravel website](http://laravel.com)
- [Laravel Turkiye website](http://www.laravel.gen.tr)
- [MeWebStudio website](http://www.mewebstudio.com)

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity55

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

2555d ago

Major Versions

1.0 → 2.02019-07-02

### Community

Maintainers

![](https://www.gravatar.com/avatar/4f90273c1af18683e57a33a3b2ae1482a0e9555dda419d649e34ef81fbbd543f?d=identicon)[canon1014](/maintainers/canon1014)

---

Top Contributors

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

---

Tags

captchalumen CaptchaCaptcha for api

### Embed Badge

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

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

###  Alternatives

[mews/captcha

Laravel 5/6/7/8/9/10/11/12 Captcha Package

2.6k5.7M88](/packages/mews-captcha)[unisharp/laravel-filemanager

A file upload/editor intended for use with Laravel 5 to 10 and CKEditor / TinyMCE

2.1k3.4M81](/packages/unisharp-laravel-filemanager)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9772.3M122](/packages/roots-acorn)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[flarum/core

Delightfully simple forum software.

201.4M2.2k](/packages/flarum-core)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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