captcha

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2021 License: Apache-2.0, MIT Imports: 5 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Captcha

type Captcha interface {
	Question() (string, error)
	Validate(input string) (bool, error)
}

func NewBannerCaptcha

func NewBannerCaptcha() Captcha
Example
package main

import (
	"fmt"
	"math/rand"

	"moul.io/captcha/captcha"
)

func main() {
	rand.Seed(42)
	captcha := captcha.NewBannerCaptcha()
	question, _ := captcha.Question()
	fmt.Println(question)

	valid, _ := captcha.Validate("lorem")
	fmt.Println(valid)

	valid, _ = captcha.Validate("ipsum")
	fmt.Println(valid)

	valid, _ = captcha.Validate("HRUKP")
	fmt.Println(valid)

	valid, _ = captcha.Validate("hrukp")
	fmt.Println(valid)

	valid, _ = captcha.Validate("\n hRuKP\t \n\n \t")
	fmt.Println(valid)

	valid, _ = captcha.Validate("dolor")
	fmt.Println(valid)

}
Output:

_                _
| |_   _ _  _  _ | |__ _ __
| ' \ | '_|| || || / /| '_ \
|_||_||_|   \_,_||_\_\| .__/
                      |_|
false
false
true
true
true
false

func NewMathCaptcha

func NewMathCaptcha() Captcha
Example
package main

import (
	"fmt"
	"math/rand"

	"moul.io/captcha/captcha"
)

func main() {
	rand.Seed(42)
	captcha := captcha.NewMathCaptcha()
	question, _ := captcha.Question()
	fmt.Println(question)

	valid, _ := captcha.Validate("42")
	fmt.Println(valid)

	valid, _ = captcha.Validate("lorem ipsum")
	fmt.Println(valid)

	valid, _ = captcha.Validate("1 + 3")
	fmt.Println(valid)

	valid, _ = captcha.Validate("4")
	fmt.Println(valid)

	valid, _ = captcha.Validate("\n 4\t \n\n \t")
	fmt.Println(valid)

}
Output:

1 + 3
false
false
false
true
true

func NewRandomCaptcha

func NewRandomCaptcha() Captcha
Example
package main

import (
	"fmt"
	"math/rand"

	"moul.io/captcha/captcha"
)

func main() {
	rand.Seed(42)

	// first captcha
	c := captcha.NewRandomCaptcha()
	question, _ := c.Question()
	fmt.Println(question)

	// second captcha
	c = captcha.NewRandomCaptcha()
	question, _ = c.Question()
	fmt.Println(question)

}
Output:

3 + 4
       _    _
 _ __ | |_ | |_  _  _  ___
| '_ \|  _||  _|| || |/ -_)
| .__/ \__| \__| \_,_|\___|
|_|

Jump to

Keyboard shortcuts

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