captchaStore
介绍
基于base64Captcha开发的验证码存储驱动,由于base64Captcha类库生成的验证码只支持内存存储,故而当你在分布式环境中使用该类库时就会出现问题,造成正确的验证验证不通过的情况,因此开发了captchaStore的存储驱动
软件架构
该仓库是基于base64Captcha 以及 cache 的store
存储接口开发的验证码永久存储驱动,目前支持redis以及memcache的存储方案,
如果这还不能满足您的需要,您还可以扩展
安装教程
go get -u gitee.com/aesoper/captchaStore
使用说明
话不多说直接贴测试代码
import (
"gitee.com/aesoper/cache"
"gitee.com/aesoper/cache/redis"
"github.com/mojocn/base64Captcha"
"testing"
"time"
)
func TestCustomCaptchaStore(t *testing.T) {
driver := &base64Captcha.DriverDigit{
Height: 40,
Width: 150,
Length: 4,
MaxSkew: 1,
DotCount: 1,
}
c, err := cache.New(cache.Cfg{
Driver: "redis",
Redis: redis.Options{
Addr: "localhost:6379",
},
})
if err != nil {
t.Errorf("init cache failed: %s", err)
}
store := NewCustomCaptchaStore(c, time.Minute * 5, false)
captcha := base64Captcha.NewCaptcha(driver, store)
// 生成验证码base64字符串
_, _, err = captcha.Generate()
if err != nil {
t.Errorf("generate captcha failed: %s", err)
}
}
参与贡献
- Fork 本仓库
- 新建 Feat_xxx 分支
- 提交代码
- 新建 Pull Request
感谢
- base64Captcha
- cache
码云特技
- 使用 Readme_XXX.md 来支持不同的语言,例如 Readme_en.md, Readme_zh.md
- 码云官方博客 blog.gitee.com
- 你可以 https://gitee.com/explore 这个地址来了解码云上的优秀开源项目
- GVP 全称是码云最有价值开源项目,是码云综合评定出的优秀开源项目
- 码云官方提供的使用手册 https://gitee.com/help
- 码云封面人物是一档用来展示码云会员风采的栏目 https://gitee.com/gitee-stars/