This commit is contained in:
suyl
2021-07-07 18:59:57 +08:00
parent ee1f00ab29
commit 21737e5cd9
5 changed files with 70 additions and 4 deletions

View File

@@ -8,6 +8,7 @@ import (
"github.com/dchest/captcha"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
"math/rand"
"net/http"
"strings"
"time"
@@ -28,6 +29,18 @@ func init() {
uncommonInitialismsReplacer = strings.NewReplacer(uncommonInitialismsForReplacer...)
}
var (
letterBytes = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
)
func RandStringBytes(n int) string {
b := make([]byte, n)
for i := range b {
b[i] = letterBytes[rand.Intn(len(letterBytes))]
}
return string(b)
}
func Captcha(c *gin.Context, length ...int) {
l := captcha.DefaultLen
w, h := 107, 36