shetabit/captcha
Composer 安装命令:
composer require shetabit/captcha
包简介
Laravel 5 CAPTCHA Integration Package
README 文档
README
This packages works with multiple drivers, and you can create custom drivers if there are not available in the current drivers list (below list).
Laravel Captcha
This is a Laravel Package for captcha Integration. This package supports Laravel 5.4+.
This packages works with multiple drivers, and you can create custom drivers if there are not available in the current drivers list (below list).
List of contents
List of available drivers
- Simple : a simple image captcha.
- Others are under way.
you can create your own custom driver if not exists in the list , read the
Create custom driverssection.
Install
Via Composer
$ composer require shetabit/captcha
Configure
If you are using Laravel 5.5 or higher then you don't need to add the provider and alias.
In your config/app.php file add these two lines.
# In your providers array. 'providers' => [ ... Shetabit\Captcha\Provider\CaptchaServiceProvider::class, ], # In your aliases array. 'aliases' => [ ... 'Payment' => Shetabit\Captcha\Facade\Captcha::class, ],
then run php artisan vendor:publish to publish config/captcha.php file in your config directory.
In the config file you can set the default driver to use for all your payments. But you can also change the driver at runtime.
Choose what gateway you would like to use in your application. Then make that as default driver so that you don't have to specify that everywhere. But, you can also use multiple gateways in a project.
// Eg. if you want to use simple. (simple is the driver's name) 'default' => 'simple',
Then see the configs in the drivers array.
'drivers' => [ 'simple' => [ 'middleware' => ['web'], // middleware 'route' => 'captcha', // route name 'characters' => 'ABCDEFGHIKJLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz123456789', 'width' => 230, 'height' => 70, 'foregroundColors' => ['2980b9','2E9FFF','FF1166','000000','22EE99'], 'backgroundColor' => '#FFF', 'letterSpacing' => 6, 'fontFamily' => resource_path('views/vendor/captchaSimpleDriver/assets/fonts/DroidSerif.ttf'), 'fontSize' => 30, 'length' => [4, 6], 'scratches' => [5, 8], 'sensitive' => false, 'sessionKey' => 'captcha', ], ... ]
How to use
you have 2 steps to go
- add captcha in forms
- add validation
Add captcha in forms
In your code, use it like the below:
<form> ... {!! captcha() !!} ... </form>
if you use simple driver, you can change the styles and UI easily,
just have a look on resources/views/vendor/captchaSimpleDriver.blade.php
Validation
in order to validate forms wich use captcha, you can use captcha validation role.
The below example shows every thing you need to know about captcha validation:
... $request->validate([ 'email' => 'required|email', 'password' => 'required|string', 'captcha' => 'required|captcha', ]); ...
Create custom drivers:
First you have to add the name of your driver, in the drivers array and also you can specify any config parameters you want.
'drivers' => [ 'simple' => [...], 'my_driver' => [ ... # Your Config Params here. ] ]
Now you have to create a Driver Map Class that will be used to pay invoices.
In your driver, You just have to extend Shetabit\Captcha\Abstracts\Driver.
Ex. You created a class : App\Packages\CaptchaDriver\MyDriver.
namespace App\Packages\CaptchaDriver; use Illuminate\Support\ServiceProvider; use Shetabit\Captcha\Abstracts\Driver; class MyDriver extends Driver { protected $serviceProvider; /** * Driver settings. * * @var object */ protected $settings; public function __construct(ServiceProvider $serviceProvider, $settings) { $this->serviceProvider = $serviceProvider; $this->settings = (object) $settings; } /** you must write your captcha generation logic in the below method. **/ public function generate() { ... // create captcha view and return it return View::make('yourCustomDriverView'); } /** you must write your captcha verification logic in the below method. **/ public function verify($token = null) { ... $storedToken = ... if (empty($this->settings->sensitive)) { $storedToken = mb_strtolower($storedToken); $token = mb_strtolower($token); } return $token == $storedToken; } }
Once you create that class you have to specify it in the captcha.php config file map section.
'map' => [ ... 'my_driver' => App\Packages\CaptchaDriver\MyDriver::class, ]
Note:- You have to make sure that the key of the map array is identical to the key of the drivers array.
Change log
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING and CONDUCT for details.
Security
If you discover any security related issues, please email hashemm364@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
shetabit/captcha 适用场景与选型建议
shetabit/captcha 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 60 次下载、GitHub Stars 达 3, 最近一次更新时间为 2019 年 03 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「captcha」 「laravel5 Captcha」 「laravel5.2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 shetabit/captcha 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 shetabit/captcha 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 shetabit/captcha 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Simple Laravel 6 Captcha Package
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Diese Contao 4 Erweiterung stellt Google reCAPTCHA V2 in Form eines neuen Formularfeldes im Formulargenerator bereit. This extension provides Google reCAPTCHA V2 in the form of a new form field in the form generator of Contao Open Source CMS.
Laravel helpers for dev
Two Captcha
Send SMS and SMS Notification via Mailjet for Laravel
统计信息
- 总下载量: 60
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2019-03-04