.
このコミットが含まれているのは:
コミット
96a2709f33
11
main.go
11
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)
|
||||
}
|
||||
|
|
読み込み中…
新しいイシューから参照