前言

为了确保网络安全,咱们网站采纳了文字点选验证码来验证用户身份。文字点选验证码是一种简略而无效的验证机制,通过要求用户点击相干图像来辨别实在用户和机器人。它不仅能够避免歹意攻打,还能提供用户敌对的验证体验。

劣势

在文字点选验证码中,用户将面对一个蕴含多个图像的界面。用户须要依据批示点击与给定条件相符的图像。这些条件能够是点击所有显示食物的图片,或者点击所有带有交通工具的图像。通过这样的验证形式,零碎可能无效辨别实在用户和机器人,进步网站的安全性。

文字点选验证码的劣势在于其简洁性和可操作性。用户只需点击几个图像就能实现验证,而无需输出简单的验证码。这不仅缩小了用户的繁琐操作,还进步了用户的满意度。

实现代码

  • HTML代码
<script src="captcha.js"></script><script>kg.captcha({    // 绑定元素,验证框显示区域    bind: "#captchaBox",    // 验证胜利事务处理    success: function(e) {        console.log(e);    },    // 验证失败事务处理    failure: function(e) {        console.log(e);    },    // 点击刷新按钮时触发    refresh: function(e) {        console.log(e);    }});</script><div id="captchaBox">载入中 ...</div>
  • Python代码
from wsgiref.simple_server import make_serverfrom KgCaptchaSDK import KgCaptchadef start(environ, response):    # 填写你的 AppId,在利用治理中获取    AppID = "AppID"    # 填写你的 AppSecret,在利用治理中获取    AppSecret = "AppSecret"    request = KgCaptcha(AppID, AppSecret)    # 填写应用服务域名,在利用治理中获取    request.appCdn = "https://cdn6.kgcaptcha.com"    # 申请超时工夫,秒    request.connectTimeout = 10    # 用户id/登录名/手机号等信息,当安全策略中的防控等级为3时必须填写    request.userId = "kgCaptchaDemo"    # 应用其它 WEB 框架时请删除 request.parse,应用框架提供的办法获取以下相干参数    parseEnviron = request.parse(environ)    # 前端验证胜利后颁发的 token,有效期为两分钟    request.token = parseEnviron["post"].get("kgCaptchaToken", "")  # 前端 _POST["kgCaptchaToken"]    # 客户端IP地址    request.clientIp = parseEnviron["ip"]    # 客户端浏览器信息    request.clientBrowser = parseEnviron["browser"]    # 去路域名    request.domain = parseEnviron["domain"]    # 发送申请    requestResult = request.sendRequest()    if requestResult.code == 0:        # 验证通过逻辑解决        html = "验证通过"    else:        # 验证失败逻辑解决        html = f"{requestResult.msg} - {requestResult.code}"    response("200 OK", [("Content-type", "text/html; charset=utf-8")])    return [bytes(str(html), encoding="utf-8")]httpd = make_server("0.0.0.0", 8088, start)  # 设置调试端口  http://localhost:8088/httpd.serve_forever()

最初

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