Skip to main content

generate

Function generate 

Source
pub fn generate() -> String
Expand description

A new random token: TOKEN_BYTES secure random bytes as URL-safe base64 without padding (43 characters).

Show or email it once and store only its digest.

§Panics

If the platform’s secure random generator is unavailable (WebCrypto on Workers, the OS generator natively), which does not happen on supported targets.

§Examples

let token = ocre::token::generate();
assert_eq!(token.len(), 43);
assert!(token.chars().all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_'));
assert_ne!(token, ocre::token::generate());