RustPass/src/main.rs

22 lines
696 B
Rust
Raw Normal View History

2023-01-10 17:09:06 +00:00
use std::env;
2023-01-10 16:37:01 +00:00
fn main() {
2023-01-10 17:09:06 +00:00
// Take in two command line arguments, one i32 and one str
let args: Vec<String> = env::args().collect();
let new_password_length: i32 = args[1].parse().unwrap();
let allowed_chars: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-=`~!@#$%^&*()_+[]\\{}|;':\",./<>?";
// Generate a random string of length n
let mut new_password = String::new();
for _ in 0..new_password_length {
2023-01-10 17:22:51 +00:00
new_password.push(
allowed_chars.chars()
.nth(rand::random::<usize>() % allowed_chars.len())
.unwrap()
);
2023-01-10 17:09:06 +00:00
}
// Print the new password
println!("{}", new_password);
2023-01-10 16:37:01 +00:00
}