summary refs log tree commit diff stats
path: root/password/randstr.go
blob: 86ae9a1838d4157d2e8c8d57908d647389af2dfc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
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)
}