captcha

package module
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: MIT Imports: 8 Imported by: 0

README

Go SVG Captcha

Package captcha provides an easy to use

PkgGoDev Build Status codecov Go Report Card

Why did I create another SVG captcha package?

I want a simple package. It should be flexible and not rely on rendering images but rather return HTML SVG code.

Install

    go get -u github.com/reu98/go-svg-captcha

Usage

    import captcha "github.com/reu98/go-svg-captcha"

    func main() {
        option := captcha.OptionText
        result, err := captcha.CreateByText(option)
        if err != nil {
            log.Fatalln(err)
        }

        // Text
        fmt.Printf("Text: %v", (*result).Text)

        // HTML SVG
        fmt.Printf("SVG: %v", (*result).Data)
    }

Documentation | Example Basic

Sample image

image image

Compatibility

This package uses embedding from Go 1.21. If you're using a version before 1.21, please upgrade to 1.21 to utilize this package.

Changelog

Changelog

Contributing

If your found a bug, please contribute! see contributing.md for more detail.

License

MIT

Roadmap

  • Finish Documentation
  • Generate multiple captchas
  • Write image
  • Upload the image to the cloud
  • Create a captcha storage to use with the API

Documentation

Overview

Package captcha provides an easy to use

Index

Constants

View Source
const (
	MathOperatorPlus  mathOperator = "+"
	MathOperatorMinus mathOperator = "-"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type OptionMath

type OptionMath struct {
	// The width of the SVG captcha
	// Default: 150
	Width uint16

	// The height of the SVG captcha
	// Default: 50
	Height uint16

	// The font size in the captcha
	// Default: 16
	FontSize uint8

	// Path font
	FontPath string

	// The color of the characters in the captcha.
	// True: the characters will have individual colors.
	// False: The characters will be gray
	// Default: false
	IsColor bool

	// Invert the colors.
	// Default: false
	IsInverse bool

	// The number of lines in the captcha
	// Default: 1
	Curve uint8

	// Background color of the SVG captcha
	// Default: Transperant
	BackgroundColor color.Color

	// The operation for the mathematical calculation
	// Supports addition (+) and subtraction (-) operations
	// If there's no specified operation, it will automatically choose one.
	MathOperator mathOperator

	// The minimum value for a number in the operation
	// Default: 1
	MathMin uint8

	// The maximum value for a number in the operation.
	// Default: 9
	MathMax uint16
}

type OptionText

type OptionText struct {
	// The length of the random string
	// Default: 4
	Size uint8

	// The width of the SVG captcha
	// Default: 150
	Width uint16

	// The height of the SVG captcha
	// Default: 50
	Height uint16

	// The font size in the captcha
	// Default: 16
	FontSize uint8

	// The color of the characters in the captcha.
	// True: the characters will have individual colors.
	// False: The characters will be gray
	// Default: false
	IsColor bool

	// Invert the colors.
	// Default: false
	IsInverse bool

	// The number of lines in the captcha
	// Default: 1
	Curve uint8

	// Background color of the SVG captcha
	// Default: Transperant
	BackgroundColor color.Color

	// Remove unacceptable characters from the captcha.
	IgnoreCharacters string

	// Path font
	FontPath string

	// The characters that can be displayed in the captcha.
	// Default: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
	CharactersPreset string

	// Generate With Text
	// Note: Text is optional. If not provided, it will be generated randomly
	Text string
}

type Result

type Result struct {
	// A random string or the result of an operation.
	Text string

	// The HTML code snippet for SVG.
	Data string
}

func CreateByMath

func CreateByMath(option OptionMath) (*Result, error)

CreateByMath: Generate a new captcha. It will return a captcha with an operation like 1 + 1.

func CreateByText

func CreateByText(option OptionText) (*Result, error)

CreateByText: generate a new captcha

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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