Browse Source

超时控制

wangshan 5 months ago
parent
commit
c1cd2fc07c
3 changed files with 8 additions and 4 deletions
  1. 2 2
      gocaptcha/start.go
  2. 1 1
      gocaptcha/start_test.go
  3. 5 1
      gocaptcha/verify.go

+ 2 - 2
gocaptcha/start.go

@@ -109,8 +109,8 @@ func Get(sess *httpsession.Session, checkCode string, w http.ResponseWriter, r *
 	//计次
 	times++
 	globalStore.Set(code, RandomDigits(len([]rune(code))))
-	b := VerifyString(code, code)
-	fmt.Println(b)
+	//b := VerifyString(code, code)
+	//fmt.Println(b)
 	redis.Put("other", cacheKey, times, int(ttl))
 	sess.Set(checkCode, code)
 	w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")

+ 1 - 1
gocaptcha/start_test.go

@@ -23,6 +23,6 @@ func TestCaptcha(t *testing.T) {
 }
 
 func TestVerify(t *testing.T) {
-	b := VerifyString("E4MA", "E4MA")
+	b := VerifyString("JHPC", "JHPC")
 	fmt.Println(b)
 }

+ 5 - 1
gocaptcha/verify.go

@@ -25,7 +25,11 @@ func Verify(id string, digits []byte) bool {
 // 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 == "" {
+	if id == "" || digits == "" {
+		return false
+	}
+	realId := globalStore.Get(id, true)
+	if realId == nil {
 		return false
 	}
 	if strings.TrimSpace(id) == strings.TrimSpace(digits) {