switch to crypto/rand
parent
9353e3f414
commit
3d877ea184
|
@ -1,10 +1,11 @@
|
||||||
package invites
|
package invites
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/rand"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"errors"
|
"errors"
|
||||||
"math/rand"
|
"math/big"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -53,7 +54,6 @@ func ConnectDB() (*sql.DB, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateCode(email string) string {
|
func generateCode(email string) string {
|
||||||
rand.Seed(time.Now().Unix())
|
|
||||||
|
|
||||||
charset := "abcdefghijklmnopqrztuvwxyz"
|
charset := "abcdefghijklmnopqrztuvwxyz"
|
||||||
charset += strings.ToUpper(charset)
|
charset += strings.ToUpper(charset)
|
||||||
|
@ -62,8 +62,14 @@ func generateCode(email string) string {
|
||||||
|
|
||||||
code := []byte{}
|
code := []byte{}
|
||||||
|
|
||||||
|
max := big.NewInt(int64(len(charset)))
|
||||||
for len(code) < codeLen {
|
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, ' ')
|
code = append(code, ' ')
|
||||||
|
|
Loading…
Reference in New Issue