From 6cc6b6d70fde6dbba626d9858f53efbce232a546 Mon Sep 17 00:00:00 2001 From: Harvey Kandola Date: Mon, 25 Jul 2016 11:40:26 -0700 Subject: [PATCH] GenerateRandom function added --- core/api/util/password.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/core/api/util/password.go b/core/api/util/password.go index da7411a4..c549fc97 100644 --- a/core/api/util/password.go +++ b/core/api/util/password.go @@ -1,11 +1,11 @@ // Copyright 2016 Documize Inc. . 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 // // You can operate outside the AGPL restrictions by purchasing // Documize Enterprise Edition and obtaining a commercial license -// by contacting . +// by contacting . // // https://documize.com @@ -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)