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) }