MCPcopy
hub / github.com/knadh/listmonk / generateRandomString

Function generateRandomString

cmd/utils.go:77–89  ·  view source on GitHub ↗

generateRandomString generates a cryptographically random, alphanumeric string of length n.

(n int)

Source from the content-addressed store, hash-verified

75
76// generateRandomString generates a cryptographically random, alphanumeric string of length n.
77func generateRandomString(n int) (string, error) {
78 const dictionary = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
79 var bytes = make([]byte, n)
80
81 if _, err := rand.Read(bytes); err != nil {
82 return "", err
83 }
84 for k, v := range bytes {
85 bytes[k] = dictionary[v%byte(len(dictionary))]
86 }
87
88 return string(bytes), nil
89}
90
91// strHasLen checks if the given string has a length within min-max.
92func strHasLen(str string, min, max int) bool {

Callers 4

makeFilenameFunction · 0.85
doLoginMethod · 0.85
doForgotPasswordMethod · 0.85
UploadMediaMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected