MCPcopy Create free account
hub / github.com/openclaw/gogcli / generateAdminUserPassword

Function generateAdminUserPassword

internal/cmd/admin_common.go:19–53  ·  view source on GitHub ↗
(length int)

Source from the content-addressed store, hash-verified

17)
18
19func generateAdminUserPassword(length int) (string, error) {
20 if length < 8 {
21 length = 8
22 }
23 const lower = "abcdefghijklmnopqrstuvwxyz"
24 const upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
25 const digits = "0123456789"
26 const special = "!@#$%^&*()_+-=[]{}|;:,.<>?"
27 const all = lower + upper + digits + special
28
29 sets := []string{lower, upper, digits, special}
30 b := make([]byte, length)
31 for i, set := range sets {
32 ch, err := adminUserRandChar(set)
33 if err != nil {
34 return "", err
35 }
36 b[i] = ch
37 }
38 for i := len(sets); i < length; i++ {
39 ch, err := adminUserRandChar(all)
40 if err != nil {
41 return "", err
42 }
43 b[i] = ch
44 }
45 for i := len(b) - 1; i > 0; i-- {
46 j, err := adminUserRandInt(i + 1)
47 if err != nil {
48 return "", err
49 }
50 b[i], b[j] = b[j], b[i]
51 }
52 return string(b), nil
53}
54
55func adminUserRandChar(set string) (byte, error) {
56 if len(set) == 0 {

Callers 1

RunMethod · 0.85

Calls 2

adminUserRandCharFunction · 0.85
adminUserRandIntFunction · 0.85

Tested by

no test coverage detected