-
Notifications
You must be signed in to change notification settings - Fork 0
/
random.go
47 lines (41 loc) · 974 Bytes
/
random.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package utils
import (
"fmt"
"image/color"
"math/rand"
"time"
"github.com/mojocn/base64Captcha"
)
func GenerateRandomKey(timestamp int64) []byte {
var data = []byte(fmt.Sprintf("%dcubing-pro-key", timestamp))
for len(data) < 32 {
data = append(data, '=')
}
return data[:32]
}
func RandomString(length int) string {
const charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
seededRand := rand.New(rand.NewSource(time.Now().UnixNano()))
b := make([]byte, length)
for i := range b {
b[i] = charset[seededRand.Intn(len(charset))]
}
return string(b)
}
// MathRandomConfig 生成图形化算术验证码配置
func MathRandomConfig() *base64Captcha.DriverMath {
mathType := &base64Captcha.DriverMath{
Height: 200,
Width: 300,
NoiseCount: 0,
ShowLineOptions: base64Captcha.OptionShowHollowLine,
BgColor: &color.RGBA{
R: 40,
G: 30,
B: 89,
A: 29,
},
Fonts: nil,
}
return mathType
}