diff options
author | =Corey Hulen <corey@hulen.com> | 2015-12-09 15:42:48 -0800 |
---|---|---|
committer | =Corey Hulen <corey@hulen.com> | 2015-12-09 15:42:48 -0800 |
commit | 9fbe16c17b6b435d0737e15be2d06fddd76798cc (patch) | |
tree | cb46cde227454e23fdb3be9b4f83552820f5ab93 /model/utils.go | |
parent | 84aa572f67cc41d59690a73f080d0f6c81be4ae0 (diff) | |
download | chat-9fbe16c17b6b435d0737e15be2d06fddd76798cc.tar.gz chat-9fbe16c17b6b435d0737e15be2d06fddd76798cc.tar.bz2 chat-9fbe16c17b6b435d0737e15be2d06fddd76798cc.zip |
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) |