mirror of
https://github.com/documize/community.git
synced 2025-07-27 09:09:44 +02:00
GenerateRandom function added
This commit is contained in:
parent
7d38102eb6
commit
6cc6b6d70f
1 changed files with 9 additions and 9 deletions
|
@ -1,11 +1,11 @@
|
||||||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||||
//
|
//
|
||||||
// This software (Documize Community Edition) is licensed under
|
// This software (Documize Community Edition) is licensed under
|
||||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||||
//
|
//
|
||||||
// You can operate outside the AGPL restrictions by purchasing
|
// You can operate outside the AGPL restrictions by purchasing
|
||||||
// Documize Enterprise Edition and obtaining a commercial license
|
// Documize Enterprise Edition and obtaining a commercial license
|
||||||
// by contacting <sales@documize.com>.
|
// by contacting <sales@documize.com>.
|
||||||
//
|
//
|
||||||
// https://documize.com
|
// https://documize.com
|
||||||
|
|
||||||
|
@ -22,17 +22,17 @@ import (
|
||||||
|
|
||||||
// GenerateRandomPassword provides a string suitable for use as a password.
|
// GenerateRandomPassword provides a string suitable for use as a password.
|
||||||
func GenerateRandomPassword() string {
|
func GenerateRandomPassword() string {
|
||||||
c := 5
|
return GenerateRandom(5)
|
||||||
b := make([]byte, c)
|
|
||||||
_, err := rand.Read(b)
|
|
||||||
log.IfErr(err)
|
|
||||||
return hex.EncodeToString(b)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenerateSalt provides a string suitable for use as a salt value.
|
// GenerateSalt provides a string suitable for use as a salt value.
|
||||||
func GenerateSalt() string {
|
func GenerateSalt() string {
|
||||||
c := 20
|
return GenerateRandom(20)
|
||||||
b := make([]byte, c)
|
}
|
||||||
|
|
||||||
|
// GenerateRandom returns a string of the specified length using crypo/rand
|
||||||
|
func GenerateRandom(size int) string {
|
||||||
|
b := make([]byte, size)
|
||||||
_, err := rand.Read(b)
|
_, err := rand.Read(b)
|
||||||
log.IfErr(err)
|
log.IfErr(err)
|
||||||
return hex.EncodeToString(b)
|
return hex.EncodeToString(b)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue