Skip to content

Commit

Permalink
Fix verification code generation
Browse files Browse the repository at this point in the history
  • Loading branch information
songquanpeng committed Nov 5, 2022
1 parent a988285 commit 12f3194
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions common/verification.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@ func GenerateVerificationCode(length int) string {
}

func GenerateAllNumberVerificationCode(length int) string {
min := math.Pow10(length)
max := math.Pow10(length+1) - 1
return strconv.Itoa(rand.Intn(int(max-min)) + int(min))
min := math.Pow10(length - 1)
max := math.Pow10(length) - 1
code := strconv.Itoa(rand.Intn(int(max-min)) + int(min))
if GetWeChatIDByCode(code) != "" {
SysError("repeated verification code detected")
return GenerateAllNumberVerificationCode(length + 1)
}
return code
}

func RegisterWeChatCodeAndID(code string, id string) {
Expand Down

0 comments on commit 12f3194

Please sign in to comment.