blob: 90e66a5819aa250df59d2791c2855b4332e2148f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
package util
import (
"crypto/rand"
"encoding/base64"
)
var enc = base64.URLEncoding
func NewRandID(n int) (string, error) {
data := make([]byte, enc.DecodedLen(n))
_, err := rand.Read(data)
if err != nil {
return "", err
}
return enc.EncodeToString(data), nil
}
func NewSessionID() (string, error) {
return NewRandID(24)
}
func NewCSRFToken() (string, error) {
return NewRandID(24)
}
|