summary refs log tree commit diff stats
path: root/password/randstr.go
diff options
context:
space:
mode:
Diffstat (limited to 'password/randstr.go')
-rw-r--r--password/randstr.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/password/randstr.go b/password/randstr.go
new file mode 100644
index 0000000..86ae9a1
--- /dev/null
+++ b/password/randstr.go
@@ -0,0 +1,13 @@
+package password
+
+import (
+	"crypto/rand"
+	"encoding/base64"
+)
+
+// RandStr will return a random base64 encoded string of length n.
+func RandStr(n int) string {
+	b := make([]byte, n/2)
+	rand.Read(b)
+	return base64.StdEncoding.EncodeToString(b)
+}