all repos — captcha @ a6788822d7fb0a37e90eb280867c61958737d746

Go package captcha implements generation and verification of image and audio CAPTCHAs.

example: add "Try another one" link; ignore /xxx.

Only return page for root path /, return 404 for any other, such as
/favicon.ico.
Dmitry Chestnykh dmitry@codingrobots.com
Wed, 27 Apr 2011 15:54:27 +0200
commit

a6788822d7fb0a37e90eb280867c61958737d746

parent

1f1174743d98634f77933e5e1298c21024e825d6

1 files changed, 7 insertions(+), 2 deletions(-)

jump to
M example/main.goexample/main.go

@@ -12,6 +12,10 @@

var formTemplate = template.MustParse(formTemplateSrc, nil) func showFormHandler(w http.ResponseWriter, r *http.Request) { + if r.URL.Path != "/" { + http.NotFound(w, r) + return + } d := struct { CaptchaId string JavaScript string

@@ -27,9 +31,10 @@

func processFormHandler(w http.ResponseWriter, r *http.Request) { if !captcha.VerifyString(r.FormValue("captchaId"), r.FormValue("captchaSolution")) { io.WriteString(w, "Wrong captcha solution! No robots allowed!\n") - return + } else { + io.WriteString(w, "Great job, human! You solved the captcha.\n") } - io.WriteString(w, "Great job, human! You solved the captcha.\n") + io.WriteString(w, "<br><a href='/'>Try another one</a>") } func main() {