go to achieve the verification code

rely

"github.com/mojocn/base64Captcha"

 Official Preview

achieve

import (
	cp "github.com/mojocn/base64Captcha"
	"image/color"
)

type captcha struct {
	c *cp.Captcha
}

//创建字符串验证码实例
func NewCaptcha(height, width, length int, source string) *captcha {
	driver := cp.NewDriverString(height, width, 0, cp.OptionShowHollowLine,
		length, source, &color.RGBA{0, 0, 0, 0}, []string{"Flim-Flam.ttf"})
	cape := cp.NewCaptcha(driver, cp.DefaultMemStore)
	return &captcha{cape}
}

//验证是否有效
func (r *captcha) Verify(id, answer string) bool {
	get := cp.DefaultMemStore.Get(id, false)
	if get == "" {
		return false
	}
	return r.c.Verify(id, answer, true)
}

//生成base64
func (r *captcha) Generate() (id, b64s string, err error) {
	return r.c.Generate()
}

 

Published 35 original articles · won praise 3 · views 10000 +

Guess you like

Origin blog.csdn.net/takujo/article/details/104083848