captcha

package module
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 4 Imported by: 0

README

Captcha

Mode 模式

  • String 字符串
  • Equation 算式 +,-,*

Disturb 干扰项

  • Point 点
  • Line 直线
  • Arc 弧线
  • Rotate 旋转
  • Distort 扭曲

验证码字符字体

MapleMonoNormalNL-Regular.ttf

Maple Mono

fonttools subset ./MapleMonoNormalNL-Regular.ttf --text='+-*1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'```

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check(id, code string) (bool, error)

func Create

func Create() (id, result string, img image.Image)

Create 创建验证码,返回图片对象image.Image

func CreateB64

func CreateB64() (id, result, data string, err error)

CreateB64 创建验证码,返回图片base64

Example
package main

import (
	"fmt"

	"github.com/mulan-ext/captcha"
	"github.com/mulan-ext/captcha/equation"
)

func init() {
	captcha.SetGlobal(equation.NewEquation(2))
}

func main() {
	id, result, data, err := captcha.CreateB64()
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(id)
	fmt.Println(data)
	if ok, _ := captcha.Check(id, "xxxx"); ok {
		fmt.Println("test check")
	} else if ok, _ := captcha.Check(id, result); ok {
		fmt.Println("ok")
	} else {
		fmt.Println("fail")
	}
}

func CreateBytes

func CreateBytes() (id, result string, buf []byte, err error)

CreateBytes 创建验证码,返回图片数据[]byte

func SetGlobal

func SetGlobal(m core.ICaptcha)

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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