1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-25 08:09:43 +02:00

GenerateRandom function added

This commit is contained in:
Harvey Kandola 2016-07-25 11:40:26 -07:00
parent 7d38102eb6
commit 6cc6b6d70f

View file

@ -22,17 +22,17 @@ import (
// GenerateRandomPassword provides a string suitable for use as a password.
func GenerateRandomPassword() string {
c := 5
b := make([]byte, c)
_, err := rand.Read(b)
log.IfErr(err)
return hex.EncodeToString(b)
return GenerateRandom(5)
}
// GenerateSalt provides a string suitable for use as a salt value.
func GenerateSalt() string {
c := 20
b := make([]byte, c)
return GenerateRandom(20)
}
// GenerateRandom returns a string of the specified length using crypo/rand
func GenerateRandom(size int) string {
b := make([]byte, size)
_, err := rand.Read(b)
log.IfErr(err)
return hex.EncodeToString(b)