Skip to content

Package captcha is a middleware that provides captcha service for Macaron.

License

Notifications You must be signed in to change notification settings

go-macaron/captcha

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

captcha

Middleware captcha a middleware that provides captcha service for Macaron.

API Reference

Installation

go get github.com/macaron-contrib/captcha

Usage

// main.go
import (
	"github.com/Unknwon/macaron"
	"github.com/macaron-contrib/cache"
	"github.com/macaron-contrib/captcha"
)

func main() {
  	m := macaron.Classic()
	m.Use(cache.Cacher())
	m.Use(captcha.Captchaer())
	
	m.Get("/", func(ctx *macaron.Context, cpt *captcha.Captcha) string {
		if cpt.VerifyReq(ctx.Req) {
			return "valid captcha"
		}
		return "invalid captcha"
	})

	m.Run()
}
<!-- templates/hello.tmpl -->
{{.Captcha.CreateHtml}}

Options

captcha.Captchaer comes with a variety of configuration options:

// ...
m.Use(captcha.Captchaer(captcha.Options{
	URLPrefix:			"/captcha/", 	// URL prefix of getting captcha pictures.
	FieldIdName:		"captcha_id", 	// Hidden input element ID.
	FieldCaptchaName:	"captcha", 		// User input value element name in request form.
	ChallengeNums:		6, 				// Challenge number.
	Expiration:			600, 			// Captcha expiration time in seconds.
	CachePrefix:		"captcha_", 	// Cache key prefix captcha characters.
}))
// ...

License

This project is under Apache v2 License. See the LICENSE file for the full license text.

About

Package captcha is a middleware that provides captcha service for Macaron.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages