关于验证码:干货验证码的常见类型总结

2次阅读

共计 1684 个字符,预计需要花费 5 分钟才能阅读完成。

前言

验证码是一种辨别用户是计算机和人的公共全自动程序。简略来说,验证码就是验证操作是人还是机器。上面我就总结一下常见的验证码类型都有哪些?

数字、字母组合

这种模式最为常见,也很简略。有的是独自应用这两种,也有的是数字、字母混合而成,为了进步辨认难度,有的会增加烦扰线,如在背景中增加烦扰线。

<?php
// 抛弃输入缓冲区的内容 **
ob_clean();

// 创立画布
$image = imagecreatetruecolor(110, 30);

// 设置红色底
$bgColor = imagecolorallocate($image, 255, 255, 255);
imagefill($image, 0, 0, $bgColor);

// 增加四个随机数字字母
for($i=0;$i<4;$i++) {
    $fontSize = 6;
    // 随机调配色彩
    $fontColor = imagecolorallocate($image, rand(0, 120), rand(0, 120), rand(0, 120));
    // 生成内容
    $data = "abcdefghijkmnpqrstuvwxy3456789";
    // 如果内容为空,从新输入 1 个
    do {$fontCont = substr($data, rand(0, strlen($data)), 1);
    } while ($fontCont == '');
    // 设置范畴
    $x = ($i*110/4)+rand(5, 10);
    $y = rand(5, 10);
    // 图片退出数字
    imagestring($image, $fontSize, $x, $y, $fontCont, $fontColor);
} 

// 增加烦扰点元素
for($j=0;$j<200;$j++) {
    // 点色彩
    $pointColor = imagecolorallocate($image, rand(50, 200), rand(50, 200), rand(50, 200));
    imagesetpixel($image, rand(1, 99), rand(1, 29), $pointColor);
}

// 增加烦扰线元素
for($z=0;$z<4;$z++) {
    // 生成色彩线
    $lineColor = imagecolorallocate($image, rand(80, 220), rand(80, 220), rand(80, 220));
    imageline($image, rand(1, 99), rand(1, 29), rand(1, 99), rand(1, 29), $lineColor);
}

header("Content-type:image/png");
// 输入图片
imagepng($image);
// 销毁内存中的图片
imagedestroy($image);

?>

短信验证码

随着手机的遍及,很多 APP 都是用手机号注册的。为了验证手机号码的真实性,避免歹意注册,通常会向手机发送验证码。网上有专门的短信发送平台,向电信运营商领取短信费用,接入即可应用。

图片辨认

依据提醒,点击对应的元素。逻辑解题能力联合图形符号等元素辨认能力。实用于平安要求超高的业务场景。应用 KgCaptcha,在用户控制台设置验证类型,多种类型抉择,如滑动拼图、文字点选、语序点选、字体辨认、空间推理。

<script src="captcha.js?appid=xxx"></script>
<script>
kg.captcha({
    // 绑定元素,验证框显示区域
    bind: "#captchaBox2",
    // 验证胜利事务处理
    success: function(e) {console.log(e);
    },
    // 验证失败事务处理
    failure: function(e) {console.log(e);
    },
    // 点击刷新按钮时触发
    refresh: function(e) {console.log(e);
    }
});
</script>
<div id="captchaBox2"> 载入中 ...</div>

最初

SDK 开源地址:https://github.com/KgCaptcha,顺便做了一个演示:https://www.kgcaptcha.com/demo/

正文完
 0