验证码扩展 Barrett-captcha

码农软件 · 软件分类 · 验证码(Captcha) · 2019-04-22 08:44:46

软件介绍

Barrett-captcha
验证码扩展库

使用

一、安装

composer require barrett/captcha

 二、初始化配置
引入本扩展库后,在实例化时可以传递配置参数,用于处理不同的场景。
$Captcha = new barrett\Captcha(['setZh'=>true,'length'=>4]);

> 配置表如下

参数名参数类型默认值说明
keystringBarrett验证码加密key
destroyBooleanBoolean验证成功后是否销毁
expireinteger1800验证码过期时间(s)
lengthinteger5验证码长度
setZhBooleanfalse使用中文验证码
widthinteger180图片验证码默认宽度
heightinteger50图片验证码默认高度
fontSizeinteger20验证码字体大小(px)
fontTtfstring 验证码字体,不设置随机获取
useImgBgBooleanfalse验证码字体,不设置随机获取
useCurveBooleantrue是否画混淆曲线
useNoiseBooleantrue是否添加杂点
bgarray[243, 251, 254]背景颜色

 二、创建验证码
本扩展目前支持:图形验证码、数字验证码(短信用)两种,使用方法如下:
> 创建图形验证码

$Captcha = new barrett\Captcha();
return $Captcha->createImg('user');

> 创建短信验证码

$Captcha = new barrett\Captcha();
//createNum方法会返回被创建的验证码
$code = $Captcha->createNum('user');
//使用短信发送数字验证码
$Sms->sendToPhone($code['data]);

> 验证码效验

$Captcha = new barrett\Captcha();
return $Captcha->check($_POST,'user');

如输出结果异常请检查页面头部信息是否正常!如:Content-type:image/png 是否设置

 三、场景标识
用例:客户更改已绑定的手机号,需要在同一个页面生成两个验证码(原手机验证码、新手机验证码)。
1.原手机创建验证码加入唯一场景标识:

$old = $Captcha->createNum('old');

2.新手机创建验证码同样加入唯一场景标识:

$new = $Captcha->createNum('new');

3.当用户提交数据时则根据唯一场景标识来检测对应场景的验证码是否正确,而不会出现相同页面多次调用后不能效验的问题。

本文地址:https://codercto.com/soft/d/4119.html

Pro Django

Pro Django

Marty Alchin / Apress / 2008-11-24 / USD 49.99

Django is the leading Python web application development framework. Learn how to leverage the Django web framework to its full potential in this advanced tutorial and reference. Endorsed by Django, Pr......一起来看看 《Pro Django》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

html转js在线工具
html转js在线工具

html转js在线工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换