actix_session/storage/
utils.rs

1use rand::distributions::{Alphanumeric, DistString as _};
2
3use crate::storage::SessionKey;
4
5/// Session key generation routine that follows [OWASP recommendations].
6///
7/// [OWASP recommendations]: https://cheatsheetseries.owasp.org/cheatsheets/Session_Management_Cheat_Sheet.html#session-id-entropy
8pub fn generate_session_key() -> SessionKey {
9    Alphanumeric
10        .sample_string(&mut rand::thread_rng(), 64)
11        .try_into()
12        .expect("generated string should be within size range for a session key")
13}