25 lines
472 B
Go
25 lines
472 B
Go
|
package auth
|
||
|
|
||
|
import (
|
||
|
"crypto/rand"
|
||
|
"math/big"
|
||
|
mrand "math/rand"
|
||
|
)
|
||
|
|
||
|
const (
|
||
|
stateLength = 32
|
||
|
stateChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-"
|
||
|
)
|
||
|
|
||
|
func GenerateState() string {
|
||
|
b := make([]byte, stateLength)
|
||
|
for i := range b {
|
||
|
num, err := rand.Int(rand.Reader, big.NewInt(int64(len(stateChars))))
|
||
|
if err != nil {
|
||
|
num = big.NewInt(mrand.Int63n(int64(len(stateChars))))
|
||
|
}
|
||
|
b[i] = stateChars[num.Int64()]
|
||
|
}
|
||
|
return string(b)
|
||
|
}
|