use crypto/rand

This commit is contained in:
dhax 2017-09-26 23:39:23 +02:00
parent 4f5abfbd70
commit 03e7b58b64
6 changed files with 44 additions and 26 deletions

View file

@ -1,20 +1,20 @@
package auth
import (
"math/rand"
"time"
"crypto/rand"
)
func init() {
rand.Seed(time.Now().UnixNano())
}
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
func randStringBytes(n int) string {
b := make([]byte, n)
for i := range b {
b[i] = letterBytes[rand.Intn(len(letterBytes))]
buf := make([]byte, n)
_, err := rand.Read(buf)
if err != nil {
panic(err)
}
return string(b)
for k, v := range buf {
buf[k] = letterBytes[v%byte(len(letterBytes))]
}
return string(buf)
}