mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-20 17:57:54 +00:00
修改随机字符串生成方法
This commit is contained in:
+15
-5
@@ -7,8 +7,13 @@ import (
|
||||
"golang.org/x/crypto/scrypt"
|
||||
)
|
||||
|
||||
func generateRandString(length int) string {
|
||||
var chars = []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_=+,.?/:;{}[]`~")
|
||||
const (
|
||||
symbol = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_=+,.?/:;{}[]`~"
|
||||
letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
)
|
||||
|
||||
func generateRandString(length int, s string) string {
|
||||
var chars = []byte(s)
|
||||
clen := len(chars)
|
||||
if clen < 2 || clen > 256 {
|
||||
panic("Wrong charset length for NewLenChars()")
|
||||
@@ -37,12 +42,17 @@ func generateRandString(length int) string {
|
||||
|
||||
// GenerateRandomKey20 生成20位随机字符串
|
||||
func GenerateRandomKey20() string {
|
||||
return generateRandString(20)
|
||||
return generateRandString(20, symbol)
|
||||
}
|
||||
|
||||
// GenerateRandomKey16 生成6为随机字符串
|
||||
// GenerateRandomKey16 生成16为随机字符串
|
||||
func GenerateRandomKey16() string {
|
||||
return generateRandString(6)
|
||||
return generateRandString(16, symbol)
|
||||
}
|
||||
|
||||
// GenerateRandomKey6 生成6为随机字符串
|
||||
func GenerateRandomKey6() string {
|
||||
return generateRandString(6, letter)
|
||||
}
|
||||
|
||||
// SetPassword 根据明文密码和加盐值生成密码
|
||||
|
||||
Reference in New Issue
Block a user