Giter Club home page Giter Club logo

captcha's Introduction

验证码服务

目前在 mac centos6.x ubuntu14 上测试通过

demo.gif


准备工作

依赖安装: golang imagemagic

验证成功:

pkg-config --cflags --libs MagickWand

go version

没有报错说明安装成功

下载并编译

git clone https://github.com/jianxinio/captcha/

或者 下载 并解压

进入captcha文件夹后运行 source install.sh

Downloading necessary files 这步可能耗时很久,后面留意观察错误,如果下载完后持续报错可能是 imagemagic 安装有误

如果一切顺利,可以看到多了一个 build 文件夹,其中

  1. bin 为可执行文件夹
  2. assets 为使用到的静态资源文件夹
  3. tmp 为缓存验证码文件

除了 build 文件夹外,其他文件不会再被使用

启动

进入到 bin 文件夹,./captcha 即可启动。

见到 Init success. 的提示说明初始化缓存生成成功。此时可以在 tmp 文件夹中看到 100 张验证码。

线上环境请自备守护进程

程序集成

访问 localhost:8001 即可见到验证码内容(格式为 base64(buffer)|result)。

使用时需要先 split('|') 然后将 base64 解密后给前端。

get '/captcha' do
  captcha = Faraday.get settings.captcha_server
  captcha_arr = captcha.body.split('|')
  @session['captcha_result'] = captcha_arr[1]
  content_type 'image/gif'
  Base64.decode64 captcha.body.split('|')[0]
end

高级配置

BriefDesign 中有详细的设计文档。

config.json 说明:

initial_count 初始化时产生的验证码数量
check_interval 检查使用量间隔
threshold 更新验证码阀值
update_count 更新的验证码数量

如果访问量较大,建议提高 initial_count 以及 update_count

更新配置文件后 reload 操作:

reload 只支持 initial_count 以及 update_count 的修改

操作方法: kill -USR2 pid

开源协议

MIT

captcha's People

Contributors

daizongxyz avatar vincenting avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.