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