MCPcopy Create free account
hub / github.com/supabase/auth / SecureAlphanumeric

Function SecureAlphanumeric

internal/crypto/crypto.go:170–184  ·  view source on GitHub ↗

SecureAlphanumeric generates a secure random alphanumeric string using standard library

(length int)

Source from the content-addressed store, hash-verified

168
169// SecureAlphanumeric generates a secure random alphanumeric string using standard library
170func SecureAlphanumeric(length int) string {
171 if length < 8 {
172 length = 8
173 }
174
175 // Calculate bytes needed for desired length
176 // base32 encoding: 5 bytes -> 8 chars
177 numBytes := (length*5 + 7) / 8
178
179 b := make([]byte, numBytes)
180 must(io.ReadFull(rand.Reader, b))
181
182 // Use standard library's base32 without padding
183 return strings.ToLower(base32.StdEncoding.WithPadding(base32.NoPadding).EncodeToString(b))[:length]
184}

Callers 4

createRefreshTokenFunction · 0.92
TestSecureTokenFunction · 0.85

Calls 1

mustFunction · 0.85

Tested by 1

TestSecureTokenFunction · 0.68