catpcha.go 621 B

1234567891011121314151617181920212223242526272829303132333435
  1. package utl
  2. import (
  3. "github.com/mojocn/base64Captcha"
  4. )
  5. var (
  6. store = base64Captcha.DefaultMemStore
  7. )
  8. type DigitCatpcha struct {
  9. h *base64Captcha.Captcha
  10. }
  11. func NewDigitCatpcha(length int) *DigitCatpcha {
  12. driver := &base64Captcha.DriverDigit{
  13. Height: 80,
  14. Width: 240,
  15. Length: length,
  16. MaxSkew: 0.7,
  17. DotCount: 80,
  18. }
  19. return &DigitCatpcha{
  20. h: base64Captcha.NewCaptcha(driver, store),
  21. }
  22. }
  23. func (self *DigitCatpcha) Gen() (id, b64 string, err error) {
  24. id, b64, err = self.h.Generate()
  25. return
  26. }
  27. func (self *DigitCatpcha) Verify(id, value string) bool {
  28. return store.Verify(id, value, true)
  29. }