captchaStore

package module
v0.0.0-...-8d788c0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

README

captchaStore

介绍

基于base64Captcha开发的验证码存储驱动,由于base64Captcha类库生成的验证码只支持内存存储,故而当你在分布式环境中使用该类库时就会出现问题,造成正确的验证验证不通过的情况,因此开发了captchaStore的存储驱动

软件架构

该仓库是基于base64Captcha 以及 cache 的store 存储接口开发的验证码永久存储驱动,目前支持redis以及memcache的存储方案, 如果这还不能满足您的需要,您还可以扩展

安装教程
  1. 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)
	}
}
参与贡献
  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request
感谢
  1. base64Captcha
  2. cache
码云特技
  1. 使用 Readme_XXX.md 来支持不同的语言,例如 Readme_en.md, Readme_zh.md
  2. 码云官方博客 blog.gitee.com
  3. 你可以 https://gitee.com/explore 这个地址来了解码云上的优秀开源项目
  4. GVP 全称是码云最有价值开源项目,是码云综合评定出的优秀开源项目
  5. 码云官方提供的使用手册 https://gitee.com/help
  6. 码云封面人物是一档用来展示码云会员风采的栏目 https://gitee.com/gitee-stars/

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultCaptchaIdPrefix = "captcha"

Functions

This section is empty.

Types

type CustomCaptchaStore

type CustomCaptchaStore struct {
	// contains filtered or unexported fields
}

func NewCustomCaptchaStore

func NewCustomCaptchaStore(cache factory.Cache, expiration time.Duration, caseSensitive bool) *CustomCaptchaStore

func (*CustomCaptchaStore) Get

func (s *CustomCaptchaStore) Get(id string, clear bool) string

func (*CustomCaptchaStore) Set

func (s *CustomCaptchaStore) Set(id string, value string)

func (*CustomCaptchaStore) Verify

func (s *CustomCaptchaStore) Verify(id, answer string, clear bool) bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL