captcha

package module
v0.0.0-...-9fd04ad Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 21, 2021 License: MIT Imports: 9 Imported by: 0

README

captcha

about

captcha is a basic package for creating/managing captchas, written entirely in Go. It allows the user to generate captchas on the fly using a random string generator and the gg library for rendering. /dev/shm is used as the workspace for these, as they should only live for a moment before the deferred cleanup function runs and deletes them.

The generator creates a gradient using random numbers for various parts to add some variation, writes the text to the image in a random-ish font color and then makes a random-ish number of iterations over the image adding random polygons - these should make it harder for machines to read the image.

usage

usage is trivial, when you need a captcha for something you can generate a new Captcha with New(), then run Generate(), which will generate the captcha and write it to the disk. The location of the file can be accessed with the File() function. The Cleanup() function must always be run (and should typically be deferred so that it will run even if the function panics) unless you're using this to generate a bunch of captchas to store. the value of the captcha is in Text(), and can be used to validate the user input against the value of the captcha.

captcha := captcha.New()
captcha.Generate()
defer captcha.Cleanup()
fmt.Println("the file is at", captcha.File(), "which means I can serve it with http.ServeFile or whatever.")

product

this produces random captchas like the below:

Sample 1 Sample 2 Sample 3 Sample 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Captcha

type Captcha struct {
	// contains filtered or unexported fields
}

func New

func New() *Captcha

func (*Captcha) Cleanup

func (c *Captcha) Cleanup()

func (*Captcha) File

func (c *Captcha) File() string

func (*Captcha) Generate

func (c *Captcha) Generate()

func (*Captcha) Text

func (c *Captcha) Text() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL