Random strings for cookie values (#1122)

This commit is contained in:
SpedNSFW
2021-02-23 13:40:43 +11:00
committed by GitHub
parent 14230d7b52
commit acbdee76de
5 changed files with 60 additions and 6 deletions

17
pkg/utils/strings.go Normal file
View File

@@ -0,0 +1,17 @@
package utils
import (
"math/rand"
"time"
)
var characters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890")
func RandomSequence(n int) string {
b := make([]rune, n)
rand.Seed(time.Now().UnixNano())
for i := range b {
b[i] = characters[rand.Intn(len(characters))]
}
return string(b)
}