captcha

package
v0.0.0-...-4a740ba Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2022 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StateCreated state = iota
	StateLastAnswerNotValid
	StateSolved
)

Captcha State

Variables

View Source
var (
	ErrCaptchaNotFound       = errors.New("CaptchaNotFound", "Given CaptchaID point to the captcha that not exist")
	ErrCaptchaExpired        = errors.New("CaptchaExpired", "Given CaptchaID point to the captcha that expired")
	ErrCaptchaAnswerNotValid = errors.New("CaptchaAnswerNotValid", "Given answer for captcha not valid")
	ErrCaptchaNotSolved      = errors.New("CaptchaNotSolved", "Given CaptchaID point to the captcha not solved yet, Solve it before use it to prove human being")
)

package errors

Functions

This section is empty.

Types

type AudioFormat

type AudioFormat uint8

AudioFormat indicate

type ImageFormat

type ImageFormat uint8

ImageFormat indicate

const (
	ImageFormatPNG ImageFormat = iota
	ImageFormatJPEG
)

Supported image format

type Language

type Language uint8

Language indicate

const (
	LanguageEnglish Language = iota
)

supported languages

type PhraseCaptcha

type PhraseCaptcha struct {
	ID       [16]byte
	Answer   string
	ExpireIn int64
	State    state
	Image    []byte // In requested lang & format
	Audio    []byte // In requested lang & format
}

PhraseCaptcha store

type PhraseCaptchas

type PhraseCaptchas struct {
	Len        uint8       // Number of captcha solution. can't be more than 16!
	Difficulty uint8       // 0:very-easy, 1:easy, 2:medium, 3:hard, 4:very-hard, 5:extreme-hard
	Type       uint8       // 0:Number(625896), 1:Word(A19Cat), 2:Math(+ - * /),
	Duration   int64       // The number of seconds indicate expiration time of captchas
	ImageSize  image.Point // Standard width & height of a captcha image.
	Pool       map[[16]byte]*PhraseCaptcha
	// contains filtered or unexported fields
}

PhraseCaptchas store

func NewDefaultPhraseCaptchas

func NewDefaultPhraseCaptchas() (pcs *PhraseCaptchas)

NewDefaultPhraseCaptchas use to make new captchas with defaults values!

func (*PhraseCaptchas) Check

func (pcs *PhraseCaptchas) Check(captchaID [16]byte) error

Check return true if captcha exits and solved otherwise returns false!

func (*PhraseCaptchas) Get

func (pcs *PhraseCaptchas) Get(captchaID [16]byte) (pc *PhraseCaptcha)

Get return exiting captcha if exits otherwise returns nil!

func (*PhraseCaptchas) GetAudio

func (pcs *PhraseCaptchas) GetAudio(captchaID [16]byte, lang Language, audioFormat AudioFormat) (pc *PhraseCaptcha)

GetAudio return exiting captcha with audio generated if exits otherwise returns nil!

func (*PhraseCaptchas) NewImage

func (pcs *PhraseCaptchas) NewImage(lang Language, imageformat ImageFormat) (pc *PhraseCaptcha)

NewImage make, store and return new captcha!

func (*PhraseCaptchas) Solve

func (pcs *PhraseCaptchas) Solve(captchaID [16]byte, answer string) error

Solve check answer and return captcha state!

Jump to

Keyboard shortcuts

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