mirror of
https://git.freesoftwareextremist.com/bloat
synced 2024-11-09 16:14:11 +00:00
21 lines
338 B
Go
21 lines
338 B
Go
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 NewCSRFToken() (string, error) {
|
|
return NewRandID(24)
|
|
}
|