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:
parent
7d38102eb6
commit
6cc6b6d70f
1 changed files with 9 additions and 9 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue