このコミットが含まれているのは:
守矢諏訪子 2023-09-27 23:45:41 +09:00
コミット 96a2709f33
1個のファイルの変更8行の追加3行の削除

11
main.go
ファイルの表示

@ -2,15 +2,16 @@ package gocaptcha
import ( import (
"crypto/rand" "crypto/rand"
"math/big"
"encoding/base64" "encoding/base64"
"image" "image"
"image/color" "image/color"
"image/draw" "image/draw"
"image/png" "image/png"
"io/ioutil" "io/ioutil"
"math/big"
"strings" "strings"
"bytes" "bytes"
"log"
"golang.org/x/image/font" "golang.org/x/image/font"
"golang.org/x/image/font/sfnt" "golang.org/x/image/font/sfnt"
@ -90,10 +91,14 @@ func VerifyCaptcha(input, captchaText string) bool {
} }
func genTxt(charset string, length int) string { func genTxt(charset string, length int) string {
runes := []rune(charset)
text := make([]rune, length) text := make([]rune, length)
for i := range text { for i := range text {
randomIndex, _ := rand.Int(rand.Reader, big.NewInt(int64(len(charset)))) randomIndex, err := rand.Int(rand.Reader, big.NewInt(int64(len(runes))))
text[i] = rune(charset[randomIndex.Int64()]) if err != nil {
log.Fatal(err)
}
text[i] = runes[randomIndex.Int64()]
} }
return string(text) return string(text)
} }