| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- package utl
- import (
- "github.com/mojocn/base64Captcha"
- )
- var (
- store = base64Captcha.DefaultMemStore
- )
- // Used for generating and verify the digital captcha
- type DigitCaptcha struct {
- h *base64Captcha.Captcha
- }
- // Initializer. length is the length of the digitals
- func NewDigitCatpcha(length int) *DigitCaptcha {
- driver := &base64Captcha.DriverDigit{
- Height: 80,
- Width: 240,
- Length: length,
- MaxSkew: 0.7,
- DotCount: 80,
- }
- return &DigitCaptcha{
- h: base64Captcha.NewCaptcha(driver, store),
- }
- }
- // Generate a new captcha image
- //
- // return
- // id: is the id of the new captcha image
- // b64: captcha image in base64 format
- // err: any error
- func (self *DigitCaptcha) Gen() (id, b64 string, err error) {
- id, b64, err = self.h.Generate()
- return
- }
- // Verify if the user input is the same as digits in captcha.
- func (self *DigitCaptcha) Verify(id, value string) bool {
- return store.Verify(id, value, true)
- }
|