diff options
author | Christopher Speller <crspeller@gmail.com> | 2015-12-10 08:54:12 -0500 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2015-12-10 08:54:12 -0500 |
commit | aef16866066c8fec2529e57a9659fd3cb03acc91 (patch) | |
tree | e92ccc3cb3335238bf9b7fd376dea71454e4a1fc /model/utils.go | |
parent | 415276fa6a1af933a8b9b8f71afa81e36d9e0b13 (diff) | |
parent | 7299fd6a4c6a658b378e4df12468d302ff6a7512 (diff) | |
download | chat-aef16866066c8fec2529e57a9659fd3cb03acc91.tar.gz chat-aef16866066c8fec2529e57a9659fd3cb03acc91.tar.bz2 chat-aef16866066c8fec2529e57a9659fd3cb03acc91.zip |
Merge pull request #1688 from mattermost/fix-salts
Generate salts when empty
Diffstat (limited to 'model/utils.go')
-rw-r--r-- | model/utils.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/model/utils.go b/model/utils.go index b49b4bb24..5596b06ff 100644 --- a/model/utils.go +++ b/model/utils.go @@ -5,6 +5,7 @@ package model import ( "bytes" + "crypto/rand" "encoding/base32" "encoding/json" "fmt" @@ -81,6 +82,17 @@ func NewId() string { return b.String() } +func NewRandomString(length int) string { + var b bytes.Buffer + str := make([]byte, length+8) + rand.Read(str) + encoder := base32.NewEncoder(encoding, &b) + encoder.Write(str) + encoder.Close() + b.Truncate(length) // removes the '==' padding + return b.String() +} + // GetMillis is a convience method to get milliseconds since epoch. func GetMillis() int64 { return time.Now().UnixNano() / int64(time.Millisecond) |