GenerateSessionID creates a unique session identifier
()
| 9 | |
| 10 | // GenerateSessionID creates a unique session identifier |
| 11 | func GenerateSessionID() string { |
| 12 | bytes := make([]byte, 8) |
| 13 | if _, err := rand.Read(bytes); err != nil { |
| 14 | // This should never happen with crypto/rand, but handle gracefully |
| 15 | // Fall back to a timestamp-based ID if crypto/rand fails |
| 16 | LogError("Failed to generate cryptographic session ID, falling back to timestamp", err) |
| 17 | return GenerateTimestampID() |
| 18 | } |
| 19 | return hex.EncodeToString(bytes) |
| 20 | } |
| 21 | |
| 22 | // GenerateTimestampID creates a session ID based on current time as fallback |
| 23 | func GenerateTimestampID() string { |