|
|
@@ -8,11 +8,13 @@ var (
|
|
|
store = base64Captcha.DefaultMemStore
|
|
|
)
|
|
|
|
|
|
-type DigitCatpcha struct {
|
|
|
+// Used for generating and verify the digital captcha
|
|
|
+type DigitCaptcha struct {
|
|
|
h *base64Captcha.Captcha
|
|
|
}
|
|
|
|
|
|
-func NewDigitCatpcha(length int) *DigitCatpcha {
|
|
|
+// Initializer. length is the length of the digitals
|
|
|
+func NewDigitCatpcha(length int) *DigitCaptcha {
|
|
|
driver := &base64Captcha.DriverDigit{
|
|
|
Height: 80,
|
|
|
Width: 240,
|
|
|
@@ -20,16 +22,23 @@ func NewDigitCatpcha(length int) *DigitCatpcha {
|
|
|
MaxSkew: 0.7,
|
|
|
DotCount: 80,
|
|
|
}
|
|
|
- return &DigitCatpcha{
|
|
|
+ return &DigitCaptcha{
|
|
|
h: base64Captcha.NewCaptcha(driver, store),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func (self *DigitCatpcha) Gen() (id, b64 string, err error) {
|
|
|
+// Generate a new captcha image
|
|
|
+//
|
|
|
+// return
|
|
|
+// id: is the id of the new captcha image
|
|
|
+// b64: captcha image in base64 format
|
|
|
+// err: any error
|
|
|
+func (self *DigitCaptcha) Gen() (id, b64 string, err error) {
|
|
|
id, b64, err = self.h.Generate()
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func (self *DigitCatpcha) Verify(id, value string) bool {
|
|
|
+// Verify if the user input is the same as digits in captcha.
|
|
|
+func (self *DigitCaptcha) Verify(id, value string) bool {
|
|
|
return store.Verify(id, value, true)
|
|
|
}
|