修改随机字符串生成方法
This commit is contained in:
1 parent
2c23ef8c6d
commit
7e2e40df56
1 file changed
+15
-5
+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