captcha

package
v0.0.0-...-93b0e25 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckCaptcha

func CheckCaptcha(key, dots string) error

func EmailCaptchaVerify

func EmailCaptchaVerify(email, code string) bool

func GenEmailCaptcha

func GenEmailCaptcha(email string) (code string, err error)

func Init

func Init(rds redis.Cmdable, stroeTyp StoreTyp)

func NewMemoryStore

func NewMemoryStore(collectNum int, expiration time.Duration) *memoryStore

NewMemoryStore returns a new standard memory store for captchas with the given collection threshold and expiration time (duration). The returned store must be registered with SetCustomStore to replace the default one.

func PicVerify

func PicVerify(id, answer string) (match bool)

func SetStoreType

func SetStoreType(typ StoreTyp)

Types

type DotsCaptcha

type DotsCaptcha struct {
	ImageBase64 string
	ThumbHase64 string
	CaptchaKey  string
}

func GetActCaptcha

func GetActCaptcha() (*DotsCaptcha, error)

type PicCaptcha

type PicCaptcha struct {
	ID     string
	B64Img string
}

func GetPicCaptcha

func GetPicCaptcha() (res *PicCaptcha, err error)

type PicCaptchaIf

type PicCaptchaIf interface {
	GenerateIdQuestionAnswer() (id, question, answer string)
	DrawCaptcha(question string) (item base64Captcha.Item, err error)
}

type Store

type Store interface {
	// Set sets the digits for the captcha id.
	Set(id string, digits interface{})

	// Get returns stored digits for the captcha id. Clear indicates
	// whether the captcha must be deleted from the store.
	Get(id string, clear bool) (digits interface{})
}

An object implementing Store interface can be registered with SetCustomStore function to handle storage and retrieval of captcha ids and solutions for them, replacing the default memory store.

It is the responsibility of an object to delete expired and used captchas when necessary (for example, the default memory store collects them in Set method after the certain amount of captchas has been stored.)

type StoreTyp

type StoreTyp int
const (
	LocalStore StoreTyp = 0
	RedisStore StoreTyp = 1
)

Jump to

Keyboard shortcuts

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