base64MyCaptchaDigit

package
v0.0.0-...-115d41d Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//TxtNumbers chacters for numbers.
	TxtNumbers = "012346789"
	//TxtAlphabet characters for alphabet.
	TxtAlphabet = "ABCDEFGHJKMNOQRSTUVXYZabcdefghjkmnoqrstuvxyz"

	//MimeTypeCaptchaImage output base64 mine-type.
	MimeTypeCaptchaImage = "image/png"
)
View Source
const (
	MaxSkew = 0.7
	// DotCount Number of background circles.
	DotCount = 20
)

Variables

View Source
var (
	// GCLimitNumber The number of captchas created that triggers garbage collection used by default store.
	GCLimitNumber = 10240
	// Expiration time of captchas used by default store.
	Expiration = 10 * time.Minute
)

Functions

func CaptchaWriteToBase64Encoding

func CaptchaWriteToBase64Encoding(cap CaptchaInterface) string

CaptchaWriteToBase64Encoding converts captcha to base64 encoding string. mimeType is one of "image/png".

func VerifyCaptcha

func VerifyCaptcha(identifier, verifyValue string) bool

VerifyCaptcha by given id key and remove the captcha value in store, return boolean value.

func VerifyCaptchaAndIsClear

func VerifyCaptchaAndIsClear(identifier, verifyValue string, isClear bool) bool

VerifyCaptchaAndIsClear verify captcha, return boolean value. identifier is the captcha id, verifyValue is the captcha image value, isClear is whether to clear the value in store.

Types

type CaptchaImageDigit

type CaptchaImageDigit struct {
	CaptchaItem
	*image.Paletted
	// contains filtered or unexported fields
}

CaptchaImageDigit digits captcha Struct

func EngineDigitsCreate

func EngineDigitsCreate(id string, config modeles.ConfigDigit) *CaptchaImageDigit

EngineDigitsCreate create captcha by engine-digits with configuration.

func (*CaptchaImageDigit) BinaryEncoding

func (m *CaptchaImageDigit) BinaryEncoding() []byte

BinaryEncoding encodes an image to PNG and returns the result as a byte slice.

func (*CaptchaImageDigit) WriteTo

func (m *CaptchaImageDigit) WriteTo(w io.Writer) (int64, error)

WriteTo writes captcha image in PNG format into the given writer.

type CaptchaInterface

type CaptchaInterface interface {
	// BinaryEncoding covert to bytes
	BinaryEncoding() []byte
	// WriteTo output captcha entity
	WriteTo(w io.Writer) (n int64, err error)
}

CaptchaInterface captcha interface for captcha engine to to write staff

func GenerateCaptcha

func GenerateCaptcha(idKey string, configuration modeles.ConfigDigit) (id string, captchaInstance CaptchaInterface, verifyValue string)

type CaptchaItem

type CaptchaItem struct {
	// Content captcha entity content.
	Content string
	// VerifyValue captcha verify value.
	VerifyValue string
	// ImageWidth image width pixel.
	ImageWidth int
	// ImageHeight image height pixel.
	ImageHeight int
}

CaptchaItem captcha basic information.

type ConfigDigit

type ConfigDigit struct {

	// Height png height in pixel.
	// 图像验证码的高度像素.
	Height int
	// Width Captcha png width in pixel.
	// 图像验证码的宽度像素
	Width int
	// DefaultLen Default number of digits in captcha solution.
	// 默认数字验证长度6.
	CaptchaLen int
	// MaxSkew max absolute skew factor of a single digit.
	// 图像验证码的最大干扰洗漱.
	MaxSkew float64
	// DotCount Number of background circles.
	// 图像验证码干扰圆点的数量.
	DotCount int
}

ConfigDigit config for captcha-engine-digit.

Jump to

Keyboard shortcuts

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