mirror of
https://github.com/pocketbase/pocketbase.git
synced 2026-10-21 13:34:04 +02:00
initial public commit
This commit is contained in:
commit
3d07f0211d
484 files changed
+92412
No files matched your search
@@ -0,0 +1,21 @@
|
||||
package security
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
)
|
||||
|
||||
// RandomString generates a random string of specified length.
|
||||
//
|
||||
// The generated string is cryptographically random and matches
|
||||
// [A-Za-z0-9]+ (aka. it's transparent to URL-encoding).
|
||||
func RandomString(length int) string {
|
||||
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
|
||||
|
||||
bytes := make([]byte, length)
|
||||
rand.Read(bytes)
|
||||
for i, b := range bytes {
|
||||
bytes[i] = alphabet[b%byte(len(alphabet))]
|
||||
}
|
||||
|
||||
return string(bytes)
|
||||
}
|
||||
Reference in new issue
Block a user