MCPcopy
hub / github.com/pocketbase/pocketbase / RandomStringWithAlphabet

Function RandomStringWithAlphabet

tools/security/random.go:22–35  ·  view source on GitHub ↗

RandomStringWithAlphabet generates a cryptographically random string with the specified length and characters set. It panics if for some reason rand.Int returns a non-nil error.

(length int, alphabet string)

Source from the content-addressed store, hash-verified

20//
21// It panics if for some reason rand.Int returns a non-nil error.
22func RandomStringWithAlphabet(length int, alphabet string) string {
23 b := make([]byte, length)
24 max := big.NewInt(int64(len(alphabet)))
25
26 for i := range b {
27 n, err := cryptoRand.Int(cryptoRand.Reader, max)
28 if err != nil {
29 panic(err)
30 }
31 b[i] = alphabet[n.Int64()]
32 }
33
34 return string(b)
35}
36
37// PseudorandomString generates a pseudorandom string with the specified length.
38//

Callers 5

normalizeNameFunction · 0.92
superuserOTPCommandFunction · 0.92
recordRequestOTPFunction · 0.92
collectionScaffoldsFunction · 0.92
RandomStringFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…