captcha

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2022 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Captcha

type Captcha struct {

	// url prefix for captcha image
	URLPrefix string

	// specify captcha id input field name
	FieldIDName string
	// specify captcha result input field name
	FieldCaptchaName string

	// captcha image width and height
	StdWidth  int
	StdHeight int

	// captcha chars nums
	ChallengeNums int

	// captcha expiration seconds
	Expiration time.Duration

	// cache key prefix
	CachePrefix string
	// contains filtered or unexported fields
}

Captcha struct

func NewCaptcha

func NewCaptcha(urlPrefix string, store Storage) *Captcha

NewCaptcha create a new captcha.Captcha

func NewWithFilter

func NewWithFilter(urlPrefix string, store Storage) *Captcha

NewWithFilter create a new captcha.Captcha and auto AddFilter for serve captacha image and add a template func for output html

func (*Captcha) CreateCaptcha

func (c *Captcha) CreateCaptcha() (string, error)

CreateCaptcha create a new captcha id

func (*Captcha) CreateCaptchaHTML

func (c *Captcha) CreateCaptchaHTML() template.HTML

CreateCaptchaHTML template func for output html

func (*Captcha) Handler

func (c *Captcha) Handler(ctx *context.Context)

Handler bhojpur filter handler for serve captcha image

func (*Captcha) Verify

func (c *Captcha) Verify(id string, challenge string) (success bool)

Verify direct verify id and challenge string

func (*Captcha) VerifyReq

func (c *Captcha) VerifyReq(req *http.Request) bool

VerifyReq verify from a request

type Image added in v0.0.4

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

Image struct

func NewImage added in v0.0.4

func NewImage(digits []byte, width, height int) *Image

NewImage returns a new captcha image of the given width and height with the given digits, where each digit must be in range 0-9.

func (*Image) WriteTo added in v0.0.4

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

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

type Storage

type Storage interface {
	// Get a cached value by key.
	Get(ctx context2.Context, key string) (interface{}, error)
	// Set a cached value with key and expire time.
	Put(ctx context2.Context, key string, val interface{}, timeout time.Duration) error
	// Delete cached value by key.
	Delete(ctx context2.Context, key string) error
}

Jump to

Keyboard shortcuts

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