Skip to main content

generate_random_password

Function generate_random_password 

Source
pub fn generate_random_password() -> Password
Expand description

Generate a cryptographically secure MySQL-compatible password.

Design rationale:

  • rand::rng(): thread-local CSPRNG seeded from the OS and periodically reseeded — suitable for secrets in rand 0.9 (direct OsRng no longer implements the high-level Rng trait required by choose/shuffle)
  • choose: avoids modulo bias — uniform distribution
  • Explicit class inclusion: satisfies MySQL validate_password MEDIUM policy
  • Shuffle: removes structural bias from fixed positions

The generated password is 32 characters long and always contains at least one lowercase letter, one uppercase letter, one digit, and one symbol.

§Panics

Panics if any character set constant is empty, which cannot happen in practice as they are defined as non-empty byte string literals.