captcha: Index | Files

package captcha

import ""

Package captcha a middleware that provides captcha service for Macaron.


Package Files

captcha.go image.go siprng.go

type Captcha Uses

type Captcha struct {
    // contains filtered or unexported fields

func (*Captcha) CreateCaptcha Uses

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

func (*Captcha) CreateHtml Uses

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

func (*Captcha) SetCaptcha Uses

func (c *Captcha) SetCaptcha(cpt *Captchas, req *http.Request)

func (*Captcha) Verify Uses

func (c *Captcha) Verify() bool

verify from a request

func (*Captcha) VerifyCaptcha Uses

func (c *Captcha) VerifyCaptcha(id string, challenge string) bool

type Captchaer Uses

type Captchaer interface {
    SetCaptcha(*Captchas, *http.Request)

type Captchas Uses

type Captchas struct {

Captcha represents a captcha service.

func New Uses

func New(opts ...Options) *Captchas

NewCaptcha initializes and returns a captcha with given options.

func (*Captchas) CreateCaptcha Uses

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

create a new captcha id

func (*Captchas) CreateHtml Uses

func (c *Captchas) CreateHtml() template.HTML

tempalte func for output html

func (*Captchas) GenRandChars Uses

func (c *Captchas) GenRandChars() string

func (*Captchas) Handle Uses

func (c *Captchas) Handle(ctx *tango.Context)

Captchaer is a middleware that maps a captcha.Captcha service into the Macaron handler chain. An single variadic captcha.Options struct can be optionally provided to configure. This should be register after cache.Cacher.

func (*Captchas) Verify Uses

func (c *Captchas) Verify(id string, challenge string) bool

direct verify id and challenge string

func (*Captchas) VerifyReq Uses

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

verify from a request

type Image Uses

type Image struct {
    // contains filtered or unexported fields

func NewImage Uses

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 Uses

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

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

type Options Uses

type Options struct {
    Caches *cache.Caches
    // 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

Package captcha imports 17 packages (graph) and is imported by 8 packages. Updated 2017-06-10. Refresh now. Tools for package owners.