From 376afee183f222d9788614dffc561fee64689195 Mon Sep 17 00:00:00 2001 From: scs Date: Thu, 27 Dec 2018 22:32:14 +0000 Subject: [PATCH] more --- main.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 9101ff6..172a819 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ import ( "html/template" "log" "crypto/rand" + "encoding/base32" "net/smtp" "strings" ) @@ -144,12 +145,12 @@ func RecoverByEmail(e string) { func randBytes(n int) []byte { - const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" - b := make([]byte, n) - for i := range b { - b[i] = letterBytes[rand.Int(len(letterBytes))] - } - return b + randomBytes := make([]byte, 32) + _, err := rand.Read(randomBytes) + if err != nil { + panic(err) + } + return []byte(base32.StdEncoding.EncodeToString(randomBytes)[:n]) } func sendRegistrationEmail(recipient, username, password string) bool {