Documentation
¶
Overview ¶
Package captcha a middleware that provides captcha service for Macaron.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Captcha ¶
type Captcha struct {
SubURL string
URLPrefix string
FieldIdName string
FieldCaptchaName string
StdWidth int
StdHeight int
ChallengeNums int
Expiration int64
CachePrefix string
ColorPalette color.Palette
// contains filtered or unexported fields
}
Captcha represents a captcha service.
func NewCaptcha ¶
NewCaptcha initializes and returns a captcha with given options.
func (*Captcha) CreateCaptcha ¶
create a new captcha id
func (*Captcha) CreateHTML ¶
CreateHTML outputs HTML for display and fetch new captcha images.
func (*Captcha) GenRandChars ¶
generate rand chars with default chars
type Image ¶
func NewImage ¶
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. The digit's color is chosen by random from the colorPalette.
func (*Image) EncodedPNG ¶
EncodedPNG encodes an image to PNG and returns the result as a byte slice.
type Options ¶
type Options struct {
// Suburl path. Default is empty.
SubURL string
// URL prefix of getting captcha pictures. Default is "/captcha/".
URLPrefix string
// Hidden input element ID. Default is "captcha_id".
FieldIdName string
// User input value element name in request form. Default is "captcha".
FieldCaptchaName string
// Challenge number. Default is 6.
ChallengeNums int
// Captcha image width. Default is 240.
Width int
// Captcha image height. Default is 80.
Height int
// Captcha expiration time in seconds. Default is 600.
Expiration int64
// Cache Key prefix captcha characters. Default is "captcha_".
CachePrefix string
// ColorPalette holds a collection of primary colors used for
// the captcha's text. If not defined, a random color will be generated.
ColorPalette color.Palette
}
func PrepareOptions ¶
Click to show internal directories.
Click to hide internal directories.