🔒 random initial password

This commit is contained in:
微凉
2022-02-03 12:27:50 +08:00
parent 3201b6da76
commit 9013add749
4 changed files with 22 additions and 13 deletions

16
utils/random.go Normal file
View File

@ -0,0 +1,16 @@
package utils
import (
"math/rand"
"strings"
)
func RandomStr(n int) string {
builder := strings.Builder{}
t := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
for i := 0; i < n; i++ {
r := rand.Intn(len(t))
builder.WriteString(t[r : r+1])
}
return builder.String()
}