From 96a2709f33e6ad18c0cb67c4fa614b6f2727eaf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AB=8F=E8=A8=AA=E5=AD=90?= Date: Wed, 27 Sep 2023 23:45:41 +0900 Subject: [PATCH] . --- main.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 7ad17bb..53ec649 100644 --- a/main.go +++ b/main.go @@ -2,15 +2,16 @@ package gocaptcha import ( "crypto/rand" + "math/big" "encoding/base64" "image" "image/color" "image/draw" "image/png" "io/ioutil" - "math/big" "strings" "bytes" + "log" "golang.org/x/image/font" "golang.org/x/image/font/sfnt" @@ -90,10 +91,14 @@ func VerifyCaptcha(input, captchaText string) bool { } func genTxt(charset string, length int) string { + runes := []rune(charset) text := make([]rune, length) for i := range text { - randomIndex, _ := rand.Int(rand.Reader, big.NewInt(int64(len(charset)))) - text[i] = rune(charset[randomIndex.Int64()]) + randomIndex, err := rand.Int(rand.Reader, big.NewInt(int64(len(runes)))) + if err != nil { + log.Fatal(err) + } + text[i] = runes[randomIndex.Int64()] } return string(text) }