captcha

package
v0.0.0-...-82e7740 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2019 License: MIT Imports: 15 Imported by: 2

Documentation

Overview

Package captcha implements generation and verification of image CAPTCHAs.

A captcha solution is the sequence of digits 0-9 with the defined length.

Index

Constants

View Source
const (
	// StdWidth standard width of a captcha image.
	StdWidth = 140
	// StdHeight standard height of a captcha image.
	StdHeight = 80
)
View Source
const (
	// DefaultLen default number of digits in captcha solution.
	DefaultLen = 4
)

Variables

This section is empty.

Functions

func RandomDigits

func RandomDigits(length int) []byte

RandomDigits returns a byte slice of the given length containing pseudorandom numbers in range 0-9. The slice can be used as a captcha solution.

func SetPriority

func SetPriority(value int)

SetPriority set the priority of the logger.

func Verify

func Verify(c xhttp.Context, clear bool) bool

Verify verify captcha

func WriteImage

func WriteImage(w io.Writer, id string, length, width, height int) ([]byte, error)

WriteImage writes PNG-encoded image representation of the captcha with the given id. The image will have the given width and height.

Types

type Controller

type Controller struct {
	ImgWidth  int
	ImgHeight int
	ImgLength int
	controller.JSONController
}

Controller captcha controller.

func (*Controller) Build

func (me *Controller) Build(c xhttp.Context)

Build captcha

func (*Controller) Verify

func (me *Controller) Verify(c xhttp.Context)

Verify Ajax verify captcha

type Image

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

Image captcha image.

func NewImage

func NewImage(id string, 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

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

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

Jump to

Keyboard shortcuts

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