switch to crypto/rand

trunk
vilmibm 2023-03-10 03:21:26 +00:00
parent 9353e3f414
commit 3d877ea184
1 changed files with 9 additions and 3 deletions

View File

@ -1,10 +1,11 @@
package invites
import (
"crypto/rand"
"database/sql"
"encoding/base64"
"errors"
"math/rand"
"math/big"
"strings"
"time"
@ -53,7 +54,6 @@ func ConnectDB() (*sql.DB, error) {
}
func generateCode(email string) string {
rand.Seed(time.Now().Unix())
charset := "abcdefghijklmnopqrztuvwxyz"
charset += strings.ToUpper(charset)
@ -62,8 +62,14 @@ func generateCode(email string) string {
code := []byte{}
max := big.NewInt(int64(len(charset)))
for len(code) < codeLen {
code = append(code, charset[rand.Intn(len(charset))])
ix, err := rand.Int(rand.Reader, max)
if err != nil {
// TODO this is bad but I'm just kind of hoping it doesn't happen...often
panic(err)
}
code = append(code, charset[ix.Int64()])
}
code = append(code, ' ')