captcha of base64 image string
Base64captcha supports any unicode character and can easily be customized to support Math Chinese Korean Japanese Russian Arabic etc.
go get github.com/mojocn/[email protected]
or edit your go.mod file to
github.com/mojocn/[email protected]
go get -u github.com/mojocn/base64Captcha
For Gopher from mainland China without VPN go get golang.org/x/image failure solution:
GOPROXY=https://goproxy.iotype 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
}
There are some build-in drivers:
// 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)
}captcha.go is the entry of base64Captcha which is quite simple.
…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
}//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
}…captcha with etcd database as store
You can customize your captcha display image by implementing interface driver and interface item.
There are some example for your reference.
You can even design the captcha struct to whatever you prefer.
base64Captcha source code is licensed under the Apache Licence, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0.html).
No open issues yet, or sync has not completed.