package bot import ( "crypto/rand" "crypto/sha256" "encoding/hex" ) // GenerateToken generates a 64-character hex token using crypto/rand. func GenerateToken() string { b := make([]byte, 32) if _, err := rand.Read(b); err != nil { panic("crypto/rand failed: " + err.Error()) } return hex.EncodeToString(b) } // HashToken returns the SHA-256 hex digest of a token, suitable for storage. func HashToken(token string) string { h := sha256.Sum256([]byte(token)) return hex.EncodeToString(h[:]) } // VerifyToken checks whether the hash of the given token matches the stored hash. func VerifyToken(token, hash string) bool { return HashToken(token) == hash }