This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

core / spindle / mill / token.go
532 B 23 lines
1package mill 2 3import ( 4 "crypto/rand" 5 "crypto/sha256" 6 "encoding/base64" 7 "encoding/hex" 8) 9 10func GenerateToken() (string, error) { 11 var b [32]byte 12 if _, err := rand.Read(b[:]); err != nil { 13 return "", err 14 } 15 return base64.RawURLEncoding.EncodeToString(b[:]), nil 16} 17 18// hashes the token for persistence and comparison. a database leak never 19// exposes a usable token, and lookup avoids a secret-dependent comparison 20func HashToken(token string) string { 21 sum := sha256.Sum256([]byte(token)) 22 return hex.EncodeToString(sum[:]) 23}