Documentation ¶
Overview ¶
Package base64Captcha create base64 encoding captcha png. designed for APPs service. 创建base64格式图像验证码,为APIs服务而设计.
Index ¶
- Variables
- func GenerateCaptchaPngBase64String(identifier string, pngWidth, pngHeight, dotCount, digitsLen int, ...) string
- func GenerateCaptchaPngBase64StringDefault(identifier string) string
- func RandomDigits(length int) []byte
- func RandomId() string
- func VerifyCaptcha(identifier, digits string) bool
- type Image
- type Store
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultLen Default number of digits in captcha solution. // 默认数字验证长度. DefaultLen = 6 // CollectNum The number of captchas created that triggers garbage collection used by default store. // 默认图像验证GC清理的上限个数 CollectNum = 100000 // Expiration time of captchas used by default store. // 内存保存验证码的时限 Expiration = 10 * time.Minute // PngWidth Captcha png width in pixel. // 图像验证码的宽度像素 PngWidth = 240 // PngHeight png height in pixel. // 图像验证码的高度像素. PngHeight = 80 // MaxSkew max absolute skew factor of a single digit. // 图像验证码的最大干扰洗漱. MaxSkew = 0.7 // DotCount Number of background circles. // 图像验证码干扰圆点的数量. DotCount = 20 )
Functions ¶
func GenerateCaptchaPngBase64String ¶
func GenerateCaptchaPngBase64String(identifier string, pngWidth, pngHeight, dotCount, digitsLen int, maxSkew float64) string
GenerateCaptchaPngBase64String customize captcha image by identifier, width, height, dot-count, digits-length, skew-factor. default settings width=240 height=70 dot-count=20 digits-len=6 skew-factor=0.7. return base64 png string. 自定义参数返回base64编码的图像验证码
func GenerateCaptchaPngBase64StringDefault ¶
GenerateCaptchaPngBase64StringDefault use default value create captcha png by identifier string. return base64 png string. 默认参数生成数字图像验证码
func RandomDigits ¶
RandomDigits returns a byte slice of the given length containing pseudorandom numbers in range 0-9. The slice can be used as a captcha solution.
func RandomId ¶
func RandomId() string
RandomId returns a new random id key string. golang服务器端产生随机的idKey
func VerifyCaptcha ¶
VerifyCaptcha the captcha image. identifier is the key of the captcha. digits numbers in captcha image. return boolean value. 验证图像验证码,返回boolean.
Types ¶
type Image ¶
Image digits captcha Struct
func NewImage ¶
NewImage returns a new captcha image of the given width and height with the given digits, where each digit must be in range 0-9.
func (*Image) WriteToBase64String ¶
WriteToBase64String convert image to base64 encodeing string
type Store ¶
type Store interface { // Set sets the digits for the captcha id. Set(id string, digits []byte) // Get returns stored digits for the captcha id. Clear indicates // whether the captcha must be deleted from the store. Get(id string, clear bool) (digits []byte) }
Store An object implementing Store interface can be registered with SetCustomStore function to handle storage and retrieval of captcha ids and solutions for them, replacing the default memory store.
It is the responsibility of an object to delete expired and used captchas when necessary (for example, the default memory store collects them in Set method after the certain amount of captchas has been stored.)
func NewMemoryStore ¶
NewMemoryStore returns a new standard memory store for captchas with the given collection threshold and expiration time (duration). The returned store must be registered with SetCustomStore to replace the default one.