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

ActiveLibrary[Security](/categories/security)

risentang/lumen-captcha
=======================

captcha for lumen

v1.0(7y ago)116MITPHPPHP &gt;=5.4

Since Dec 17Pushed 7y agoCompare

[ Source](https://github.com/risentang2333/lumen55-captcha)[ Packagist](https://packagist.org/packages/risentang/lumen-captcha)[ RSS](/packages/risentang-lumen-captcha/feed)WikiDiscussions master Synced 2mo ago

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

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

[](#captcha-for-lumen)

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

注：非常感谢 [aishan/lumen-captcha](https://github.com/aishan/lumen-captcha.git)提供的无状态缓存版接口验证码， 但由于lumen5.3中的内核与lumen5.5的内核有不同。所以本人经过修改调试，弄出支持lumen5.5的无状态缓存版接口验证码。

预览效果图
-----

[](#预览效果图)

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

安装
--

[](#安装)

- 项目必须启用缓存才能使用，因为验证码和验证码绑定的uuid都是保存在缓存的。 project's `composer.json`.

```
composer require risentang/lumen-captcha
```

or

```
{
    "require": {
        "laravel/lumen-framework": "5.5.*",
        "risentang/lumen-captcha": "^1.0"
    },
    "minimum-stability": "dev"
}
```

使用
--

[](#使用)

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

```
    //验证码
    $app->register(Risentang\LumenCaptcha\CaptchaServiceProvider::class);
    class_alias('Risentang\LumenCaptcha\Facades\Captcha','Captcha');
```

配置
--

[](#配置)

在`bootstrap/app.php`中可以配置各种自定义类型的验证码属性： 更多详细配置请查看

```
/**
 * captcha配置
 */
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',
            'blur'   =>0,//模糊度
            'sharpen'   =>0,//锐化
            'contrast'   =>0,//反差
            'fontColors'=>['#339900','#ff3300','#9966ff','#3333ff'],//字体颜色
        ],
    ]
]);
```

当然，也可以不配置，默认就是default的样式，验证码有效时间5分钟。

使用范例
----

[](#使用范例)

因为lumen一般写的都是无状态的API，所以此处验证码的图片必须绑定一个uuid，获取图片验证码时，先获取验证码url地址和uuid，然后在验证时，提交验证码和uuid一并验证码。

### 生成验证码

[](#生成验证码)

获取验证码信息：

```
{站点域名}/captchaInfo/{type?}

```

其中`type`就是在配置文件中定义的验证码类型（如果你定义了的话），当然也可以不指定`type`，则默认为`default`，返回信息：

```
{
  "code": "10000",
  "msg": "success",
  "sub_code": "",
  "sub_msg": "",
  "result": {
    "captchaUrl": "{站点域名}/captcha/default/fc1d7d7f-3d8c-652a-5e92-90e9822740ad",
    "captchaUuid": "fc1d7d7f-3d8c-652a-5e92-90e9822740ad"
  }
}
```

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

#### 验证验证码

[](#验证验证码)

在请求中将验证码的值和uuid随着你的post请求一起发到服务端，在接收参数的地方做验证即可：

```
public function checkCaptcha(Request $request, $type = 'default',$captchaUuid)
    {
        $this->validate($request,[
            'captcha'=>'required|captcha:'.$captchaUuid
        ]);
        ...
    }
```

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 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

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

Unknown

Total

1

Last Release

2700d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

lumen Captchalumen SecurityCaptcha for api

### Embed Badge

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

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

###  Alternatives

[mews/captcha

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

2.6k5.5M84](/packages/mews-captcha)[unisharp/laravel-filemanager

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

2.2k3.3M73](/packages/unisharp-laravel-filemanager)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[aishan/lumen-captcha

captcha for lumen

118.5k](/packages/aishan-lumen-captcha)[flarum/core

Delightfully simple forum software.

211.3M1.9k](/packages/flarum-core)[tzsk/otp

A secure, database-free One-Time Password (OTP) generator and verifier for PHP and Laravel.

241641.4k1](/packages/tzsk-otp)

PHPackages © 2026

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