Generate passwords restricted

    0

    0

    Giovanny Gongora

    Codiga's Rust Recipes

    from a set of user defined characters

    use rand::{thread_rng, Rng};
    use rand::distributions::Alphanumeric;
    
    fn main() {
      use rand::Rng;
      const CHARSET: &[u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZ\
        abcdefghijklmnopqrstuvwxyz\
        0123456789)(*&^%$#@!~";
      const PASSWORD_LEN: usize = 30;
      let mut rng = rand::thread_rng();
      let password: String = (0..PASSWORD_LEN)
      .map(|_| {
        let idx = rng.gen_range(0..CHARSET.len());
        CHARSET[idx] as char
      })
      .collect();
      println!("{:?}", password);
    }
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.