captcha

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

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

Go to latest
Published: Jan 12, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultExpiredScanInterval = 60 * time.Second

Variables

This section is empty.

Functions

This section is empty.

Types

type Answer

type Answer string

func NewIntAnswer

func NewIntAnswer() Answer

type BaseCaptcha

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

BaseCaptcha is a base implementation of a CAPTCHA.

All derivatives that embed this struct only need to implement an Image() method.

func NewBaseCaptcha

func NewBaseCaptcha(expiry time.Duration) *BaseCaptcha

func (*BaseCaptcha) Answer

func (c *BaseCaptcha) Answer() Answer

func (*BaseCaptcha) Expiry

func (c *BaseCaptcha) Expiry() time.Time

func (*BaseCaptcha) Image

func (c *BaseCaptcha) Image(style string) *image.Image

func (*BaseCaptcha) IsSolved

func (c *BaseCaptcha) IsSolved() bool

func (*BaseCaptcha) Solve

func (c *BaseCaptcha) Solve(answer Answer) bool

type Captcha

type Captcha interface {
	// Image generates an image of a CAPTCHA according to a passed style
	// and returns a pointer to it.
	Image(style string) *image.Image
	// Answer returns a pregenerated answer.
	Answer() Answer
	// Solve compares a stored answer with a passed one.
	Solve(answer Answer) bool
	// IsSolved returns if a CAPTCHA is solved or not.
	IsSolved() bool
	// Expiry returns a date after what CAPTCHA will expire.
	Expiry() time.Time
}

Captcha interface that should be implemented by a CAPTCHA.

type CaptchaDB

type CaptchaDB interface {
	New(data string, captcha Captcha) (Captcha, ID)
	GetExpiry() time.Duration
	SetExpiry(expiry time.Duration)
	Image(id ID, style string) *image.Image
	Solve(id ID, answer Answer) bool
	IsSolved(id ID) bool
	Remove(id ID)
}

CaptchaDB interface with all necessary methods.

type ID

type ID string

ID is a CAPTCHA identifier.

func NewID

func NewID(additionalData string, answer Answer) ID

NewID generates an ID as a sha256 hash of additionalData (usually IP-address), current time, answer and more, it adds a set of random bytes and encodes all of it with base64 in raw URL variant.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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