Git Product home page Git Product logo

captcha's Introduction

Go CAPTCHA Library

GoDoc

A stateless CAPTCHA library for Go. Currently supports only image CAPTCHAs.

Image Image Image

What does “stateless” mean in this context? Images are deterministically generated and verified from an opaque key-string passed by the client. This string is generated by the server, and is encrypted and authenticated via NaCl secretbox. This means that you don't need to keep track of the CAPTCHAs you issue:

  • You generate a new Instance, which is serialized as a base64-encoded encrypted, authenticated data structure. This string is called the Key.

  • You direct the user to the appropriate image serving handler, e.g. /captcha/{Key}.gif.

  • In the response form, you include the Key as a hidden field.

  • When you receive the response, you use the passed Key to verify the correctness of the response.

  • The Key is added to a spent CAPTCHA store. By default, an in-memory store is used; you may optionally implement your own. Keys are expired from the store once their natural expiry time is reached.

Here's a usage example:

cfg := captcha.Config{
  Leeway: 1,   // allow one wrong character
  Width:  200,
  Height: 100,

  // Default expiry time 1 hour

  // EncryptionKey will be generated automatically if it is unset.
  // You must therefore set it if you have multiple servers.
}

cfg.SetFontPath(".../fonts/")

http.Handle("/captcha/", cfg.Handler("/captcha/"))

inst := cfg.NewInstance()
key  := cfg.Key(&inst)
imageURL := "/captcha/" + key

// Later

inst2, err := cfg.DecodeInstance(key)
if err != nil {
  // ...
  return
}

if cfg.Verify(inst2, userInput) {
  // CAPTCHA response was valid
}

Licence

Image warping code was taken from dchest/captcha.

© 2011-2014 Dmitry Chestnykh <[email protected]>    MIT License
© 2015 Hugo Landau <[email protected]>                  MIT License

captcha's People

Contributors

hlandau avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.