From c802a2dbc0a7638c902b2b94ab97d952e7c10290 Mon Sep 17 00:00:00 2001 From: Mike Arpaia Date: Tue, 2 Aug 2016 14:41:50 -0700 Subject: [PATCH] Cleaning up the salt generation function (#30) close #19 --- auth.go | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/auth.go b/auth.go index dfbe9190b5..9579504829 100644 --- a/auth.go +++ b/auth.go @@ -261,31 +261,14 @@ func Logout(c *gin.Context) { c.JSON(200, nil) } -const ( - letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" - letterIndex = 6 // 6 bits to represent a letter index - letterIndexMask = 1<= 0; { - if remain == 0 { - cache, remain = psrngSource.Int63(), letterIndexMax - } - if idx := int(cache & letterIndexMask); idx < len(letters) { - text[i] = letters[idx] - i-- - } - cache >>= letterIndex - remain-- + rand.Seed(time.Now().UTC().UnixNano()) + const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" + result := make([]byte, length) + for i := 0; i < length; i++ { + result[i] = chars[rand.Intn(len(chars))] } - - return string(text) + return string(result) } func HashPassword(salt, password string) ([]byte, error) {