From f832fda590783e09c5a82042854cf9081261c5ba Mon Sep 17 00:00:00 2001 From: Maximilian Date: Tue, 24 Jan 2023 12:19:53 -0600 Subject: [PATCH] Cryptographically generate the password --- src/main.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 5f6c657..6273d07 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,7 @@ use std::env; +use rand::RngCore; + fn main() { // Take in two command line arguments, one i32 and one optional String let args: Vec = env::args().collect(); @@ -34,12 +36,13 @@ fn main() { } if let Some(new_password_length) = new_password_length { // Unwrap Option in i32 + let mut rng = rand::thread_rng(); // Generate a random string of length n let mut new_password = String::new(); for _ in 0..new_password_length { new_password.push( allowed_chars.chars() - .nth(rand::random::() % allowed_chars.len()) + .nth(rng.next_u32() as usize % allowed_chars.len()) .unwrap() ); }