|
@@ -89,6 +89,9 @@ func WriteAudio(w io.Writer, id string) os.Error {
|
|
|
// The function deletes the captcha with the given id from the internal
|
|
// The function deletes the captcha with the given id from the internal
|
|
|
// storage, so that the same captcha can't be verified anymore.
|
|
// storage, so that the same captcha can't be verified anymore.
|
|
|
func Verify(id string, digits []byte) bool {
|
|
func Verify(id string, digits []byte) bool {
|
|
|
|
|
+ if digits == nil || len(digits) == 0 {
|
|
|
|
|
+ return false
|
|
|
|
|
+ }
|
|
|
reald := globalStore.getDigitsClear(id)
|
|
reald := globalStore.getDigitsClear(id)
|
|
|
if reald == nil {
|
|
if reald == nil {
|
|
|
return false
|
|
return false
|
|
@@ -96,6 +99,28 @@ func Verify(id string, digits []byte) bool {
|
|
|
return bytes.Equal(digits, reald)
|
|
return bytes.Equal(digits, reald)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// VerifyString is like Verify, but accepts a string of digits. It removes
|
|
|
|
|
+// spaces and commas from the string, but any other characters, apart from
|
|
|
|
|
+// digits and listed above, will cause the function to return false.
|
|
|
|
|
+func VerifyString(id string, digits string) bool {
|
|
|
|
|
+ if digits == "" {
|
|
|
|
|
+ return false
|
|
|
|
|
+ }
|
|
|
|
|
+ ns := make([]byte, len(digits))
|
|
|
|
|
+ for i := range ns {
|
|
|
|
|
+ d := digits[i]
|
|
|
|
|
+ switch {
|
|
|
|
|
+ case '0' <= d && d <= '9':
|
|
|
|
|
+ ns[i] = d - '0'
|
|
|
|
|
+ case d == ' ' || d == ',':
|
|
|
|
|
+ // ignore
|
|
|
|
|
+ default:
|
|
|
|
|
+ return false
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return Verify(id, ns)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// Collect deletes expired or used captchas from the internal storage. It is
|
|
// Collect deletes expired or used captchas from the internal storage. It is
|
|
|
// called automatically by New function every CollectNum generated captchas,
|
|
// called automatically by New function every CollectNum generated captchas,
|
|
|
// but still exported to enable freeing memory manually if needed.
|
|
// but still exported to enable freeing memory manually if needed.
|