mirror of
https://gitea.phreedom.club/localhost_frssoft/bloat.git
synced 2024-11-05 04:29:21 +02:00
Update random id generation algorithm
This commit is contained in:
parent
bf2cfaf0ed
commit
c9842c65b4
|
@ -69,7 +69,10 @@ func main() {
|
|||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
s.CSRFToken = util.NewCSRFToken()
|
||||
s.CSRFToken, err = util.NewCSRFToken()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = sessionRepo.Add(s)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
|
|
@ -106,8 +106,14 @@ func (svc *service) GetAuthUrl(ctx context.Context, instance string) (
|
|||
instanceURL = "https://" + instance
|
||||
}
|
||||
|
||||
sessionID = util.NewSessionId()
|
||||
csrfToken := util.NewCSRFToken()
|
||||
sessionID, err = util.NewSessionId()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
csrfToken, err := util.NewCSRFToken()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
session := model.Session{
|
||||
ID: sessionID,
|
||||
InstanceDomain: instance,
|
||||
|
|
17
util/rand.go
17
util/rand.go
|
@ -1,7 +1,8 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"crypto/rand"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -9,18 +10,22 @@ var (
|
|||
runes_length = len(runes)
|
||||
)
|
||||
|
||||
func NewRandId(n int) string {
|
||||
func NewRandId(n int) (string, error) {
|
||||
data := make([]rune, n)
|
||||
for i := range data {
|
||||
data[i] = runes[rand.Intn(runes_length)]
|
||||
num, err := rand.Int(rand.Reader, big.NewInt(int64(runes_length)))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(data)
|
||||
data[i] = runes[num.Int64()]
|
||||
}
|
||||
return string(data), nil
|
||||
}
|
||||
|
||||
func NewSessionId() string {
|
||||
func NewSessionId() (string, error) {
|
||||
return NewRandId(24)
|
||||
}
|
||||
|
||||
func NewCSRFToken() string {
|
||||
func NewCSRFToken() (string, error) {
|
||||
return NewRandId(24)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue