captcha

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultKeyPrefix 验证码答案缓存 key 前缀
	DefaultKeyPrefix = "micro.pkg:captcha:answer:"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Captcha

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

Captcha 验证码校验器

func MustNewCaptcha

func MustNewCaptcha(c Config, kvStore *xkv.Store) *Captcha

MustNewCaptcha 新建验证码校验器

func NewCaptcha

func NewCaptcha(c Config, kvStore *xkv.Store) (*Captcha, error)

NewCaptcha 新建验证码校验器

func (*Captcha) Generate

func (c *Captcha) Generate() (id, b64s, answer string, err error)

Generate 生成验证码信息

func (*Captcha) Verify

func (c *Captcha) Verify(id, answer string, clear bool) (ok bool)

Verify 校验验证码信息

type Config

type Config struct {
	KeyPrefix      string        `json:",optional"`    // 验证码答案缓存 key 前缀,为空则使用 DefaultKeyPrefix
	ImageWidth     int           `json:",default=240"` // 验证码图片宽度
	ImageHeight    int           `json:",default=80"`  // 验证码图片高度
	CodeLength     int           `json:",default=6"`   // 验证码编码长度
	CodeExpiration time.Duration `json:",default=5m"`  // 验证码编码过期时间
}

Config 验证码配置

type Store

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

Store 验证码存储器

func NewStore

func NewStore(kvStore *xkv.Store, keyPrefix string, expiration int) *Store

NewStore 新建验证码存储器

func (*Store) Get

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

Get 获取验证码信息

func (*Store) Set

func (s *Store) Set(id, value string) error

Set 存储验证码信息

func (*Store) Verify

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

Verify 校验验证码信息

Jump to

Keyboard shortcuts

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