package common

import (
	"github.com/mojocn/base64Captcha"
)

var captchaStore = base64Captcha.DefaultMemStore

var captchaDriver = base64Captcha.NewDriverString(
	40,                              // height
	120,                             // width
	0,                               // noise count (auto)
	base64Captcha.OptionShowSlimeLine, // show slime lines
	5,                               // code length
	base64Captcha.TxtSimpleCharaters, // digits+letters excluding confusing chars
	nil,                             // bg color (auto)
	nil,                             // font storage (auto)
	[]string{"wqy-microhei.ttc"},    // font files
)

var captchaInstance = base64Captcha.NewCaptcha(captchaDriver, captchaStore)

func GenerateCaptcha() (string, string, error) {
	id, b64s, _, err := captchaInstance.Generate()
	return id, b64s, err
}

func VerifyCaptcha(id, code string) bool {
	return captchaStore.Verify(id, code, true)
}
