captcha of base64 and diversity

Overview

A flexible and various captcha package

Test Go Report Card GoDoc Build Status codecov stability-stable Foundation

Base64captcha supports any unicode character and can easily be customized to support Math Chinese Korean Japanese Russian Arabic etc.

1. 📖 📖 📖 Doc & Demo

2. 🚀 🚀 🚀 Quick start

2.1 🎬 🎬 🎬 Use history version

Tag v1.2.2

go get github.com/mojocn/[email protected]

or edit your go.mod file to

github.com/mojocn/[email protected]

2.2 📥 📥 📥 Download package

go get -u github.com/mojocn/base64Captcha

For Gopher from mainland China without VPN go get golang.org/x/image failure solution:

  • go version > 1.11
  • set env GOPROXY=https://goproxy.io

2.3 🏂 🏂 🏂 How to code with base64Captcha

2.3.1 🏇 🏇 🏇 Implement Store interface or use build-in memory store

type Store interface {
	// Set sets the digits for the captcha id.
	Set(id string, value string)

	// Get returns stored digits for the captcha id. Clear indicates
	// whether the captcha must be deleted from the store.
	Get(id string, clear bool) string
	
    //Verify captcha's answer directly
	Verify(id, answer string, clear bool) bool
}

2.3.2 🏄 🏄 🏄 Implement Driver interface or use one of build-in drivers

There are some build-in drivers:

  1. Build-in Driver Digit
  2. Build-in Driver String
  3. Build-in Driver Math
  4. Build-in Driver Chinese
// Driver captcha interface for captcha engine to to write staff
type Driver interface {
	//DrawCaptcha draws binary item
	DrawCaptcha(content string) (item Item, err error)
	//GenerateIdQuestionAnswer creates rand id, content and answer
	GenerateIdQuestionAnswer() (id, q, a string)
}

2.3.3 🚴 🚴 🚴 ‍Core code captcha.go

captcha.go is the entry of base64Captcha which is quite simple.

package base64Captcha

import (
	"math/rand"
	"time"
)

func init() {
	//init rand seed
	rand.Seed(time.Now().UnixNano())
}

// Captcha captcha basic information.
type Captcha struct {
	Driver Driver
	Store  Store
}

//NewCaptcha creates a captcha instance from driver and store
func NewCaptcha(driver Driver, store Store) *Captcha {
	return &Captcha{Driver: driver, Store: store}
}

//Generate generates a random id, base64 image string or an error if any
func (c *Captcha) Generate() (id, b64s string, err error) {
	id,content, answer := c.Driver.GenerateIdQuestionAnswer()
	item, err := c.Driver.DrawCaptcha(content)
	if err != nil {
		return "", "", err
	}
	c.Store.Set(id, answer)
	b64s = item.EncodeB64string()
	return
}

//Verify by a given id key and remove the captcha value in store,
//return boolean value.
//if you has multiple captcha instances which share a same store.
//You may want to call `store.Verify` method instead.
func (c *Captcha) Verify(id, answer string, clear bool) (match bool) {
	match = c.Store.Get(id, clear) == answer
	return
}

2.3.4 🚵 🚵 🚵 ‍Generate Base64(image/audio) string

func (c *Captcha) Generate() (id, b64s string, err error) {
	id,content, answer := c.Driver.GenerateIdQuestionAnswer()
	item, err := c.Driver.DrawCaptcha(content)
	if err != nil {
		return "", "", err
	}
	c.Store.Set(id, answer)
	b64s = item.EncodeB64string()
	return
}

2.3.5 🤸 🤸 🤸 Verify Answer

//if you has multiple captcha instances which shares a same store. You may want to use `store.Verify` method instead.
//Verify by given id key and remove the captcha value in store, return boolean value.
func (c *Captcha) Verify(id, answer string, clear bool) (match bool) {
	match = c.Store.Get(id, clear) == answer
	return
}

2.3.6 🏃 🏃 🏃 ‍Full Example

// example of HTTP server that uses the captcha package.
package main

import (
	"encoding/json"
	"fmt"
	"github.com/mojocn/base64Captcha"
	"log"
	"net/http"
)

//configJsonBody json request body.
type configJsonBody struct {
	Id            string
	CaptchaType   string
	VerifyValue   string
	DriverAudio   *base64Captcha.DriverAudio
	DriverString  *base64Captcha.DriverString
	DriverChinese *base64Captcha.DriverChinese
	DriverMath    *base64Captcha.DriverMath
	DriverDigit   *base64Captcha.DriverDigit
}

var store = base64Captcha.DefaultMemStore

// base64Captcha create http handler
func generateCaptchaHandler(w http.ResponseWriter, r *http.Request) {
	//parse request parameters
	decoder := json.NewDecoder(r.Body)
	var param configJsonBody
	err := decoder.Decode(&param)
	if err != nil {
		log.Println(err)
	}
	defer r.Body.Close()
	var driver base64Captcha.Driver

	//create base64 encoding captcha
	switch param.CaptchaType {
	case "audio":
		driver = param.DriverAudio
	case "string":
		driver = param.DriverString.ConvertFonts()
	case "math":
		driver = param.DriverMath.ConvertFonts()
	case "chinese":
		driver = param.DriverChinese.ConvertFonts()
	default:
		driver = param.DriverDigit
	}
	c := base64Captcha.NewCaptcha(driver, store)
	id, b64s, err := c.Generate()
	body := map[string]interface{}{"code": 1, "data": b64s, "captchaId": id, "msg": "success"}
	if err != nil {
		body = map[string]interface{}{"code": 0, "msg": err.Error()}
	}
	w.Header().Set("Content-Type", "application/json; charset=utf-8")
	json.NewEncoder(w).Encode(body)
}

// base64Captcha verify http handler
func captchaVerifyHandle(w http.ResponseWriter, r *http.Request) {

	//parse request json body
	decoder := json.NewDecoder(r.Body)
	var param configJsonBody
	err := decoder.Decode(&param)
	if err != nil {
		log.Println(err)
	}
	defer r.Body.Close()
	//verify the captcha
	body := map[string]interface{}{"code": 0, "msg": "failed"}
	if store.Verify(param.Id, param.VerifyValue, true) {
		body = map[string]interface{}{"code": 1, "msg": "ok"}
	}

	//set json response
	w.Header().Set("Content-Type", "application/json; charset=utf-8")

	json.NewEncoder(w).Encode(body)
}

//start a net/http server
func main() {
	//serve Vuejs+ElementUI+Axios Web Application
	http.Handle("/", http.FileServer(http.Dir("./static")))

	//api for create captcha
	http.HandleFunc("/api/getCaptcha", generateCaptchaHandler)

	//api for verify captcha
	http.HandleFunc("/api/verifyCaptcha", captchaVerifyHandle)

	fmt.Println("Server is at :8777")
	if err := http.ListenAndServe(":8777", nil); err != nil {
		log.Fatal(err)
	}
}

2.3.7 Example Use Etcd as store

captcha with etcd database as store

3. 🎨 🎨 🎨 Customization

You can customize your captcha display image by implementing interface driver and interface item.

There are some example for your reference.

  1. DriverMath
  2. DriverChinese
  3. ItemChar

You can even design the captcha struct to whatever you prefer.

4. 💖 💖 💖 Thanks

5. 🍭 🍭 🍭 Licence

base64Captcha source code is licensed under the Apache Licence, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0.html).

Comments
  • generate函数提示错误

    generate函数提示错误

    大概的错误信息

    invalid argument to Intn
    /usr/local/Cellar/go/1.13.8/libexec/src/math/rand/rand.go:169 (0x119266e)
            (*Rand).Intn: panic("invalid argument to Intn")
    /usr/local/Cellar/go/1.13.8/libexec/src/math/rand/rand.go:329 (0x119309f)
            Intn: func Intn(n int) int { return globalRand.Intn(n) }
    /Users/cpp/golang/pkg/mod/github.com/mojocn/[email protected]/random_math.go:78 (0x1c8c238)
            randIntRange: return rand.Intn(to-from) + from
    /Users/cpp/golang/pkg/mod/github.com/mojocn/[email protected]/item_digit.go:165 (0x1c8af62)
            (*ItemDigit).drawDigit: y += randIntRange(-r, r)
    /Users/cpp/golang/pkg/mod/github.com/mojocn/[email protected]/driver_digit.go:70 (0x1c84034)
            (*DriverDigit).DrawCaptcha: itemDigit.drawDigit(digitFontData[n], x, y)
    /Users/cpp/golang/pkg/mod/github.com/mojocn/[email protected]/captcha.go:33 (0x1c82aee)
            (*Captcha).Generate: item, err := c.Driver.DrawCaptcha(content)
    
    
    
    opened by nagaame 7
  • 我该如何获得验证码正确的数值

    我该如何获得验证码正确的数值

    目前通过 GenerateCaptcha()VerifyCaptcha() 已经可以正常生成验证码以及验证验证码的准确性

    现在需求是 给出 正确答案以及混淆值,让用户选择以达到验证效果,我应该如何获取答案值 61

    log.Println(cap)
    
    &{{60+1=? 61 240 60} 0xc4205ba000 0}
    
    opened by du5 7
  • The b64s can not use

    The b64s can not use

    用代码生成一个DriverString类型的,最后返回的b64s无法正常显示,例如:data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPAAAAA8CAYAAABYfzddAAALs0lEQVR4nOydC5QT1f3Hv8NrF0Xd/RMl8QH5+6a6elqLOjCg06pRLFI3tdbWRyvFBz5ybGOO2tZT6LFojNZQq6hVaeujqAFb8RHsYdoyOLCoVLQgCCVw2k0WAiyPsgsLpGeWm93Zskp0nuZ9zck5+d+4MPzbzvfd334PAqCq8wXBOY47JJGIf2uiOJfg88RyVdEM6G3rJJncMZYDdDjAYjMphAmYwXAwTcHVDh5YMl8EEXN102O0Ao3+wTqzqZi8OdWxdCmAagLEAhgPYDeBzAAk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kHgDAvCbPICe4TSdjsI0vpNpODodWa+nVFlJ0+7kuzlpxAl+cMMpRWCofD/sgMl1PS8aKKKG8iBzzPMt8lS/mQtOHzjCtjG92ylqQxGGZQMISuEv5C2RPLaNteY4I/DEZZVLWAc7ncYmpnhXqdyeu9iPgDV7MamOEEqlrAj25cmAPwOJX8QMQfmFbonog/cDlZTshg2I6Tl/lZQmRUYAC4zvmxPHXpY7JofwOZ2H4SOYokP997FdkPq6szq7+nEzIY5cJeuEO16vFk3nYpW+qArLIaB2C69iwpJmCG1VR1CJ0nmko2kx0155eQfYUq3mgq+QWphRkM2yhpGKkaiKaSGQCNEX9gPDkfOb+t7BFkvHt55yb3Ocwj64HBBMxgMBiMimEhNIPhYpiAGQwXwwTMYLgYJmAGw8UwATMYLoYJmMFwMUzADIaLYQJmMFwMEzCD4WKYgBkMF/O/AAAA//8BQzGHXqbd+gAAAABJRU5ErkJggg==

    opened by Icarus9913 6
  • 我不知道是我电脑问题还是怎么回事,用demo都无法运行

    我不知道是我电脑问题还是怎么回事,用demo都无法运行

    Hello, I found that neither demo nor self configuration can run, and the error has been reported all the time 你好,我发现用demo还是自我配置都是不可以运行的,一直报错

    2019/12/13 10:30:39 EOF 2019/12/13 10:30:39 http: panic serving [::1]:61416: runtime error: invalid memory address or nil pointer dereference goroutine 25728 [running]: net/http.(*conn).serve.func1(0xc000259360) D:/use/Go/src/net/http/server.go:1767 +0x140 panic(0x712300, 0xca1940) D:/use/Go/src/runtime/panic.go:679 +0x1c0 github.com/mojocn/base64Captcha.(*DriverDigit).GenerateIdQuestionAnswer(0x0, 0xc000265d70, 0xc000092000, 0x4, 0xc0000bd800, 0xc000092030, 0xcae360) D:/path/gopath/pkg/mod/github.com/mojocn/[email protected]/driver_digit.go:46 +0x45 github.com/mojocn/base64Captcha.(*Captcha).Generate(0xc000265b10, 0x1, 0x1, 0x7e3480, 0xc000032040, 0x8, 0xc0005af9d0) D:/path/gopath/pkg/mod/github.com/mojocn/[email protected]/captcha.go:42 +0x41 main.generateCaptchaHandler(0x7e90e0, 0xc00015ba40, 0xc0000c1c00) D:/mywork/web/kongbu/main.go:52 +0x238 net/http.HandlerFunc.ServeHTTP(0x78f920, 0x7e90e0, 0xc00015ba40, 0xc0000c1c00) D:/use/Go/src/net/http/server.go:2007 +0x4b net/http.(*ServeMux).ServeHTTP(0xcae320, 0x7e90e0, 0xc00015ba40, 0xc0000c1c00) D:/use/Go/src/net/http/server.go:2387 +0x1c4 net/http.serverHandler.ServeHTTP(0xc0000520e0, 0x7e90e0, 0xc00015ba40, 0xc0000c1c00) D:/use/Go/src/net/http/server.go:2802 +0xab net/http.(*conn).serve(0xc000259360, 0x7e9620, 0xc000a5b840) D:/use/Go/src/net/http/server.go:1890 +0x87c created by net/http.(*Server).Serve D:/use/Go/src/net/http/server.go:2928 +0x38b exit status 2

    opened by yilcool 6
  • 完整案例代码运行报空指针,求指教,谢谢

    完整案例代码运行报空指针,求指教,谢谢

    2020/04/07 00:19:01 http: panic serving 127.0.0.1:8414: runtime error: invalid memory address or nil pointer dereference goroutine 48 [running]: net/http.(*conn).serve.func1(0xc0002501e0) D:/Program Files/go/src/net/http/server.go:1767 +0x140 panic(0x704740, 0xc89920) D:/Program Files/go/src/runtime/panic.go:679 +0x1c0 github.com/mojocn/base64Captcha.(*DriverDigit).GenerateIdQuestionAnswer(0x0, 0xc000305d70, 0xc0000b2000, 0x4, 0xc00011e000, 0xc0000b2030, 0xc962e0) D:/Malaysia/code/Go/fx-go/pkg/mod/github.com/mojocn/[email protected]/driver_digit.go:44 +0x45 github.com/mojocn/base64Captcha.(*Captcha).Generate(0xc000305b10, 0x1, 0x1, 0x7d27a0, 0xc000058030, 0x8, 0xc0003059d0) D:/Malaysia/code/Go/fx-go/pkg/mod/github.com/mojocn/[email protected]/captcha.go:34 +0x41

    完整示例代码运行一直报这个错误,不知道是哪里问题,求指教,谢谢

    opened by richfuns 5
  • runtime error: invalid memory address or nil pointer dereference

    runtime error: invalid memory address or nil pointer dereference

    2020/01/15 20:02:37 http: panic serving 127.0.0.1:64947: runtime error: invalid memory address or nil pointer dereference goroutine 36 [running]: net/http.(*conn).serve.func1(0xc00022e000) /usr/local/Cellar/go/1.12.4/libexec/src/net/http/server.go:1769 +0x139 panic(0x1309aa0, 0x18b27f0) /usr/local/Cellar/go/1.12.4/libexec/src/runtime/panic.go:522 +0x1b5 github.com/mojocn/base64Captcha.(*DriverDigit).GenerateIdQuestionAnswer(0x0, 0xbf7fddb76af07a38, 0x10f5c6f9d, 0x4, 0xc0001d4e00, 0xc0000cc030, 0x18be7e0) /Users/dev/go/src/github.com/mojocn/base64Captcha/driver_digit.go:44 +0x3f github.com/mojocn/base64Captcha.(*Captcha).Generate(0xc000237be8, 0x13d5c58, 0x18db068, 0x13d1f20, 0xc000084030, 0x0, 0xc000237c80) /Users/dev/go/src/github.com/mojocn/base64Captcha/captcha.go:32 +0x3d main.generateCaptchaHandler(0x13d8080, 0xc0000d60e0, 0xc00029c000) /Users/Desktop/test/capture.go:52 +0x230 net/http.HandlerFunc.ServeHTTP(0x137cfd8, 0x13d8080, 0xc0000d60e0, 0xc00029c000) /usr/local/Cellar/go/1.12.4/libexec/src/net/http/server.go:1995 +0x44 net/http.(*ServeMux).ServeHTTP(0x18be700, 0x13d8080, 0xc0000d60e0, 0xc00029c000) /usr/local/Cellar/go/1.12.4/libexec/src/net/http/server.go:2375 +0x1d6 net/http.serverHandler.ServeHTTP(0xc00008c9c0, 0x13d8080, 0xc0000d60e0, 0xc00029c000) /usr/local/Cellar/go/1.12.4/libexec/src/net/http/server.go:2774 +0xa8 net/http.(*conn).serve(0xc00022e000, 0x13d8680, 0xc000058480) /usr/local/Cellar/go/1.12.4/libexec/src/net/http/server.go:1878 +0x851 created by net/http.(*Server).Serve /usr/local/Cellar/go/1.12.4/libexec/src/net/http/server.go:2884 +0x2f4

    opened by fengjinhai 5
  • 无法在Windows下载代码

    无法在Windows下载代码

    Windows上无法创建带特殊符号的文件(28+58=?.png),请改下名字。

    grouped write of manifest, lock and vendor: error while writing out vendor tree: failed to write dep tree: failed to export github.com/mojocn/base64Captcha: error: unable to create file C:\Users\admin\AppData\Local\Temp\dep936777486\vendor\github.com\mojocn\base64Captcha\examples/static/28+58=?.png: Invalid argument
    
    opened by rsinensis 5
  • fix(redis): Fixed a get/set error not returning

    fix(redis): Fixed a get/set error not returning

    Since the previous "store.Store" interface did not return an error, the upper caller could not know that the storage error occurred. This problem will cause the upper caller to know the specific error message when a storage error occurs during the generation or verification of the verification code.

    opened by Luckyboys 4
  • 大佬好,验证码校验貌似有bug,在清除后二次验证时会返回true

    大佬好,验证码校验貌似有bug,在清除后二次验证时会返回true

    package utils
    
    import (
    	"github.com/mojocn/base64Captcha"
    	"image/color"
    )
    
    type Captcha struct {
    	Id   string
    	BS64 string
    	Code int
    }
    
    // 定义共同使用的存储
    var store = base64Captcha.DefaultMemStore
    
    // GetCaptcha 生成验证码
    func GetCaptcha() (id string, base64 string, err error) {
    	rgbaColor := color.RGBA{0, 0, 0, 0}
    	fonts := []string{"wqy-microhei.ttc"}
    	//生成driver,高,宽,背景文字的干扰,画线的条数,背景颜色的指针,字体仓库(nil为默认),字体切片(可以使用多种字体)
    	driver := base64Captcha.NewDriverMath(50, 140, 0, 1, &rgbaColor, nil, fonts)
    
    	//使用前面的driver和store 生成验证码的实例
    	captcha := base64Captcha.NewCaptcha(driver, store)
    
    	//生成验证码
    	id, base64, err = captcha.Generate()
    	return id, base64, err
    }
    
    // VerityCaptcha 校验验证码
    func VerityCaptcha(id string, ret_captcha string) bool {
    	return store.Verify(id, ret_captcha, ture) //clear 为ture 时只验证一次就销毁了,会有bug返回为true ,false不销毁
    }
    
    //调用时
    func (l *LoginController) Post() {
    	username := l.GetString("username")
    	password := l.GetString("password")
    	captcha := l.GetString("captcha")
    	captcha_id := l.GetString("captcha_id")
    
    	//验证码校验
    	fmt.Println("captcha:",captcha)
    	is_ok := utils.VerityCaptcha(captcha_id, captcha)
    	fmt.Println("is_ok:",is_ok)
    
    //我在页面上不输入验证码,第一次返回正确false,第二次返回就true了
    captcha: 
    is_ok: false
    2021/07/29 10:35:11.541 [D] [router.go:925]  |      127.0.0.1| 200 |     7.3549ms|   match| POST     /     r:/
    captcha: 
    is_ok: true
    

    刚学习go的菜鸟一枚,再者,大佬您这文档真是没法看啊,啥啥看不懂,我这还是看知了课堂里的老师教给用的

    opened by zhangbest5 3
  • goland 下载报证书问题

    goland 下载报证书问题

    GOPROXY=https://goproxy.cn,direct go version go1.16 windows/amd64

    go: github.com/mojocn/[email protected]: Get "https://proxy.golang.cn/github.com/mojocn/base64%21captcha/@v/v1.3.4.mod": x509: certificate signed by unknown authority

    opened by zh851122 3
  • More breaking API changes

    More breaking API changes

    I've run into errors in my code that uses base64Captcha that worked with previous base64Captcha versions. The errors I'm currently getting are

    default: src/captcha.go:12:17: undefined: base64Captcha.ConfigCharacter
    default: src/captcha.go:24:19: undefined: base64Captcha.ConfigCharacter
    default: src/captcha.go:75:17: undefined: base64Captcha.VerifyCaptcha
    default: src/captcha.go:103:22: undefined: base64Captcha.CaptchaInterface
    default: src/captcha.go:104:31: undefined: base64Captcha.GenerateCaptcha
    default: src/captcha.go:105:16: undefined: base64Captcha.CaptchaWriteToBase64Encoding
    

    I know the code in question worked previously, but this is the second time that changes to this package's API have broken my code. Is the API so unstable that I can't reliably use it without having to constantly uninstall and reinstall the package just to make sure that I don't have to rewrite code that shouldn't have to be rewritten? The main.go.md In the root directory of this repo even uses the previous API.

    And I'd use a previous version/tag but for compatibility reasons, I'm not (yet) using Go's module feature, and for the record, the suggested go get github.com/mojocn/[email protected] command in README.md fails with the error go: cannot use path@version syntax in GOPATH mode

    opened by Eggbertx 3
  • 中文图片显示不出来

    中文图片显示不出来

    问题: 用以下代码图片中文字有的展现不出来, 甚至有的图片一个文字都展示不出来

    示例代码:

    var param configJsonBody
    param.CaptchaType = "chinese"
    param.DriverChinese = base64Captcha.NewDriverChinese(60, 320, 0,
    0, 6, "设,在,处,消,的,频,出,可,能,论,么,没,任", &color.RGBA{R: 125, G: 125, B: 0, A: 118}, nil, []string{"wqy-microhei.ttc"})
    driver := param.DriverChinese.ConvertFonts()
    c := base64Captcha.NewCaptcha(driver, store)
    id, b64s, err := c.Generate()
    fmt.Println(fmt.Sprintf("id: %s, err: %v", id, err))
    fmt.Println(b64s)
    

    图片: image

    opened by shixiaofeia 2
  • 为啥如果有多个实例的时候,最好调用store.verify

    为啥如果有多个实例的时候,最好调用store.verify

    看到代码里面有这样一句话,没有理解原因,疑问有几个 1.是否应该设置多个实例,如果多个captcha实例,共享一个redis缓存,会不会存在ID重复的问题(redis里面用ID做的key),如果会重复后面的就会覆盖之前的val,前面的验证就会失败 2.如果不应该设置多个实例。在部署方面是不是应该起一个服务,这一个实例来提供grpc接口,其他需要验证的服务通过调用接口来实现ID的分配和销毁 3.这的注释说最好用store的verify方法,不理解这样做好处是什么,cap的verify方法不也是直接调用的store的方法吗 image

    opened by shanhuang94 1
  • feat(inmemory): verify method must check the empty id and answer.

    feat(inmemory): verify method must check the empty id and answer.

    we can use Id=<unexisted_id>, value="" to avoid captcha verify. e.g.

    curl 'https://captcha.mojotv.cn/api/verifyCaptcha' \
      -H 'content-type: application/json;charset=UTF-8' \
      --data-raw '{"ShowLineOptions":[],"CaptchaType":"string","Id":"zsTJGNGtesc9BCnfSxMv","VerifyValue":"","DriverAudio":{"Length":6,"Language":"zh"},"DriverString":{"Height":60,"Width":240,"ShowLineOptions":0,"NoiseCount":0,"Source":"1234567890qwertyuioplkjhgfdsazxcvbnm","Length":6,"Fonts":["wqy-microhei.ttc"],"BgColor":{"R":0,"G":0,"B":0,"A":0}},"DriverMath":{"Height":60,"Width":240,"ShowLineOptions":0,"NoiseCount":0,"Length":6,"Fonts":["wqy-microhei.ttc"],"BgColor":{"R":0,"G":0,"B":0,"A":0}},"DriverChinese":{"Height":60,"Width":320,"ShowLineOptions":0,"NoiseCount":0,"Source":"设想,你在,处理,消费者,的音,频输,出音,频可,能无,论什,么都,没有,任何,输出,或者,它可,能是,单声道,立体声,或是,环绕立,体声的,,不想要,的值","Length":2,"Fonts":["wqy-microhei.ttc"],"BgColor":{"R":125,"G":125,"B":0,"A":118}},"DriverDigit":{"Height":80,"Width":240,"Length":5,"MaxSkew":0.7,"DotCount":80}}' 
    
    opened by laushunyu 1
  • mat be use store.Verify()

    mat be use store.Verify()

    https://github.com/mojocn/base64Captcha/blob/1a6d007056a31d2525bb29780d37fc396634caee/captcha.go#L51

    Store.verify should be used here, otherwise custom case-insensitive authentication cannot be implemented

    opened by fifsky 0
Releases(v1.3.4)
Owner
mojocn
Coding with love
mojocn
Go library for accessing the anti-captcha.com API

go-anti-captcha Go library for accessing the anti-captcha.com API Usage See import "github.com/andrewdruzhinin/go-anti-captcha/anticaptcha" Get accoun

Andrew Druzhinin 5 Oct 20, 2019
Go code to generate Captcha letters for any TrueType font format files.

Go code to generate Captcha letters for any TrueType font format files. The code can be modified for the background and font colors. The code can be easily upgraded for distorted and rotated letters. These generated lettes can be stiched together to make captcha string.

null 0 Jan 31, 2022
Kage Solutions - Finishline & JDSports Captcha API Integration

Kage Solutions - Finishline & JDSports Captcha API Integration

Kage Solutions 0 Feb 10, 2022
[TOOL, CLI] - Filter and examine Go type structures, interfaces and their transitive dependencies and relationships. Export structural types as TypeScript value object or bare type representations.

typex Examine Go types and their transitive dependencies. Export results as TypeScript value objects (or types) declaration. Installation go get -u gi

Daniel T. Gorski 172 Dec 6, 2022
:chart_with_upwards_trend: Monitors Go MemStats + System stats such as Memory, Swap and CPU and sends via UDP anywhere you want for logging etc...

Package stats Package stats allows for gathering of statistics regarding your Go application and system it is running on and sent them via UDP to a se

Go Playgound 163 Nov 10, 2022
James is your butler and helps you to create, build, debug, test and run your Go projects

go-james James is your butler and helps you to create, build, debug, test and run your Go projects. When you often create new apps using Go, it quickl

Pieter Claerhout 56 Oct 8, 2022
GoThanks automatically stars Go's official repository and your go.mod github dependencies, providing a simple way to say thanks to the maintainers of the modules you use and the contributors of Go itself.

Give thanks (in the form of a GitHub ★) to your fellow Go modules maintainers. About GoThanks performs the following operations Sends a star to Go's r

psampaz 117 Dec 24, 2022
A simple Cron library for go that can execute closures or functions at varying intervals, from once a second to once a year on a specific date and time. Primarily for web applications and long running daemons.

Cron.go This is a simple library to handle scheduled tasks. Tasks can be run in a minimum delay of once a second--for which Cron isn't actually design

Robert K 215 Dec 17, 2022
Library to work with MimeHeaders and another mime types. Library support wildcards and parameters.

Mime header Motivation This library created to help people to parse media type data, like headers, and store and match it. The main features of the li

Anton Ohorodnyk 25 Nov 9, 2022
The new home of the CUE language! Validate and define text-based and dynamic configuration

The CUE Data Constraint Language Configure, Unify, Execute CUE is an open source data constraint language which aims to simplify tasks involving defin

null 3.4k Dec 31, 2022
Hack this repo and add your name to the list above. Creativity and style encouraged in both endeavors.

Hack this repo and add your name to the list above. Creativity and style encouraged in both endeavors.

Danger 2 Oct 1, 2021
A comprehensive training, nutrition, and social platform for martial artists and combat sport athletes

COMHRAC Comhrac (Gaelic for "Combat") is a comprehensive training, nutrition, and social platform for martial artists and combat sport athletes. Devel

Jack Hegarty 0 Oct 17, 2021
Purpose: dump slack messages, users and files using browser token and cookie.

Slack Dumper Purpose: dump slack messages, users and files using browser token and cookie. Typical usecase scenarios: You want to archive your private

Rustam 274 Jan 2, 2023
Package buildinfo provides basic building blocks and instructions to easily add build and release information to your app.

Package buildinfo provides basic building blocks and instructions to easily add build and release information to your app. This is done by replacing variables in main during build with ldflags.

null 1 Nov 14, 2021
Phalanx is a cloud-native full-text search and indexing server written in Go built on top of Bluge that provides endpoints through gRPC and traditional RESTful API.

Phalanx Phalanx is a cloud-native full-text search and indexing server written in Go built on top of Bluge that provides endpoints through gRPC and tr

Minoru Osuka 297 Dec 25, 2022
Highly extensible, customizable application launcher and window switcher written in less than 300 lines of Golang and fyne

golauncher A go application launcher A simple, highly extensible, customizable application launcher and window switcher written in less than 300 lines

Ettore Di Giacinto 45 Aug 21, 2022
Go package and associated command line utility to generate random yet human-readable names and identifiers

namegen | What's this? Go package and associated command line utility to generate random yet human-readable names and identifiers. Somewhat inspired b

Anand Varma 6 Oct 19, 2022
An application dedicated to the trivial and boring task of meal planning 📅 and generating shoppings list 🛒.

An application dedicated to the trivial and boring task of meal planning ?? and generating shoppings list ??.

Anders Wiggers 1 Mar 1, 2022
Proc-peepin - Capture process cpu and memory and send it off to influx

proc-peepin Capture process cpu and memory and send it off to influx Running loc

Brennon Loveless 0 Feb 13, 2022