lubosdz / yii2-captcha-extended
为Yii2框架提供的可配置混淆级别的扩展验证码生成器
1.0.5
2023-11-07 11:59 UTC
Requires
- php: >=7.0
- yiisoft/yii2: 2.0.*
README
Yii2 Captcha Extended是为Yii2框架编写的扩展。它增强了框架附带的原生验证码代码 - 请参阅演示。Yii 1.x版本的版本可在Yii框架扩展中找到。
特性
- 支持模式:默认、数学、数学文字、单词、逻辑
- 支持扩展字符集latin1、latin2(utf-8),包括中东和西里尔字符
- 添加视觉混淆元素:点密度、横穿线、填充区域、随机文本和背景颜色
- 模式相关选项:randomUpperLowerCase(默认模式)、resultMultiplier(数学模式)
安装
- 通过composer安装
$ composer require "lubosdz/yii2-captcha-extended" : "~1.0.0"
或者你可以在你的composer.json文件中包含以下内容
{ "require": { "lubosdz/yii2-captcha-extended" : "~1.0.0" } }
- 在控制器中定义操作,例如
SiteController
public function actions() { return [ 'captcha' => [ 'class' => 'lubosdz\captchaExtended\CaptchaExtendedAction', // optionally, set mode and obfuscation properties e.g.: 'mode' => 'math', //'mode' => CaptchaExtendedAction::MODE_MATH, //'resultMultiplier' => 5, //'lines' => 5, //'density' => 10, //'height' => 50, //'width' => 150, ], ]; }
- 在
LoginForm::rules()
中定义客户端验证
public $verifyCode; public function rules() { return [ ['verifyCode', 'lubosdz\captchaExtended\CaptchaExtendedValidator', 'captchaAction' => Url::to('/site/captcha'), ], ]; }
- 在视图中在登录表单中定义验证码字段,例如
<?php $form = ActiveForm::begin() ?> // ... <?= $form->field($model, 'verifyCode')->widget(Captcha::className(), [ 'captchaAction' => Url::to('/site/captcha'), 'template' => '<div class="text-center">{image}</div><br/> {input} ', 'imageOptions' => [ 'class' => 'img-fluid', 'style' => 'cursor:pointer; width: 100%', 'title' => Yii::t('app', 'Click to refresh the code'), ], 'options' => [ 'placeholder' => Yii::t('app', 'Verification code'), 'class' => 'form-control', ], ])->label(false) ?> // ... <?php ActiveForm::end(); ?>
-
如果需要,可以通过CLI命令
yiic message messages/config.php
收集本地化字符串并翻译验证码相关字符串。 -
由于默认情况下验证码配置为默认框架设置,你可能需要调整一些选项
mode
- default|math|mathverbal|logical|words,- 对于
words
模式,你可以替换自己的文件[words.txt]或[words.yourlanguage.txt]
- 对于
density
- 点密度 [0-100],lines
- 横穿线的数量 [0-20],fillSections
- 填充区域的数量 [0-20],letters
- 定义你自己的第一个字符集(支持UTF-8)vowels
- 定义你自己的第二个字符集(支持UTF-8)resultMultiplier
- 应用到数学模式以增加公式难度fileWords
- 到你自定义的本地化单词文件的绝对路径(支持UTF-8)randomUpperLowerCase
- 从字符集中随机混合大写和小写字母paramRefreshUrl
- 设置你自己的URL刷新参数,默认为v
- 请注意框架支持的常规属性:
width
、height
、padding
、offset
、foreColor
、backColor
、transparent
、minLength
、maxLength
等。
-
祝您使用愉快!:-)
变更日志
版本 1.0.5 - 2023年11月7日
- PHP 8.2+ 兼容性
- 默认启用REGEX中的Unicode
版本 1.0.4 - 2021年6月30日
- 更新SK、CS单词(删除了带重音的字符)
版本 1.0.3 - 2020年6月7日
- PHP 7.4+ 的微小兼容性修复
版本 1.0.2 - 2020年2月25日
- 在URL中配置刷新参数
- 更新文档
版本 1.0.1 - 2018年5月21日
- 添加CS(捷克)单词文件
- 水平居中公式
- 更新文档
版本 1.0.0 - 2018年3月28日
- 重构之前的扩展,用于Yii 1.x分支
- 添加了新的选项 - 自定义字符集、resultMultiplier、randomUpperLowerCase、Imagick支持
- 一些潜在的错误修复,例如计算像素颜色范围
- 完整的多字节(MB)支持
- 添加了对通过composer安装的支持