Added password list

This commit is contained in:
Maddox Werts 2024-06-15 16:46:56 -04:00
parent cd8a57669f
commit 790fba496c
3 changed files with 37 additions and 8 deletions

View file

@ -60,10 +60,11 @@ pub fn int_welcome(username: &String) -> String {
println!("\n - {} RUSTYPASS {} - ", COLOR_YELLOW, COLOR_RESET); println!("\n - {} RUSTYPASS {} - ", COLOR_YELLOW, COLOR_RESET);
println!("Welcome, {}{}{}!", COLOR_CYAN, username, COLOR_RESET); println!("Welcome, {}{}{}!", COLOR_CYAN, username, COLOR_RESET);
println!("Please select one of the following options: "); println!("Please select one of the following options: ");
println!("\n{}1{}) View a Password", COLOR_GREEN, COLOR_RESET); println!("\n{}1{}) List passwords", COLOR_GREEN, COLOR_RESET);
println!("{}2{}) Create a Password", COLOR_GREEN, COLOR_RESET); println!("{}2{}) View a Password", COLOR_GREEN, COLOR_RESET);
println!("{}3{}) Generate a Password", COLOR_GREEN, COLOR_RESET); println!("{}3{}) Create a Password", COLOR_GREEN, COLOR_RESET);
println!("{}4{}) Quit", COLOR_GREEN, COLOR_RESET); println!("{}4{}) Generate a Password", COLOR_GREEN, COLOR_RESET);
println!("{}5{}) Quit", COLOR_GREEN, COLOR_RESET);
io::stdin().read_line(&mut user_input).expect("Failed to read line"); io::stdin().read_line(&mut user_input).expect("Failed to read line");
// Returning what the user said // Returning what the user said
@ -177,4 +178,14 @@ pub fn int_view(manager: &mut manager::Manager) {
println!("Username:\t{}{}{}", COLOR_MAGENTA, pass_obj.user, COLOR_RESET); println!("Username:\t{}{}{}", COLOR_MAGENTA, pass_obj.user, COLOR_RESET);
println!("Passphrase:\t{}{}{}", COLOR_GREEN, pass_obj.phrase, COLOR_RESET); println!("Passphrase:\t{}{}{}", COLOR_GREEN, pass_obj.phrase, COLOR_RESET);
println!(""); println!("");
}
pub fn int_list(manager: &mut manager::Manager){
// Getting password names
let passwords: Vec<manager::Password> = manager.password_list();
// Listing out passwords
println!(" - {} All Passwords {} - ", COLOR_YELLOW, COLOR_RESET);
for i in 0..passwords.len()-1 {
println!("{0}{1}{2}) {3}{4}{2}\t({5}{6}{2})", COLOR_GREEN, i, COLOR_RESET, COLOR_CYAN, passwords[i].name, COLOR_MAGENTA, passwords[i].user);
}
} }

View file

@ -35,19 +35,21 @@ fn stage_manager(auth_profile: &mut auth::Auth) {
println!("\n"); println!("\n");
// Deciding what page we are on // Deciding what page we are on
if page == "4" { if page == "5" {
println!("Goodbye, {}{}{}!", interface::COLOR_CYAN, auth_profile.username, interface::COLOR_RESET); println!("Goodbye, {}{}{}!", interface::COLOR_CYAN, auth_profile.username, interface::COLOR_RESET);
break; break;
} else if page == "3" { } else if page == "4" {
let (pass_len, pass_num, pass_spe) = interface::int_gen(); let (pass_len, pass_num, pass_spe) = interface::int_gen();
let gen_pass: String = manager::Manager::password_generate(pass_len, pass_num, pass_spe); let gen_pass: String = manager::Manager::password_generate(pass_len, pass_num, pass_spe);
println!("Your password is: {}{}{}", interface::COLOR_GREEN, gen_pass, interface::COLOR_RESET); println!("Your password is: {}{}{}", interface::COLOR_GREEN, gen_pass, interface::COLOR_RESET);
} else if page == "2" { } else if page == "3" {
let (pass_name, pass_user, pass_phrase) = interface::int_create(); let (pass_name, pass_user, pass_phrase) = interface::int_create();
manager.password_create(pass_name.clone(), pass_user, pass_phrase); manager.password_create(pass_name.clone(), pass_user, pass_phrase);
println!("\nSuccessfully added {}{}{}!", interface::COLOR_GREEN, pass_name, interface::COLOR_RESET); println!("\nSuccessfully added {}{}{}!", interface::COLOR_GREEN, pass_name, interface::COLOR_RESET);
} else if page == "1" { } else if page == "2" {
interface::int_view(&mut manager); interface::int_view(&mut manager);
} else if page == "1" {
interface::int_list(&mut manager);
} else { } else {
println!("ERROR: Unrecognized Page!"); println!("ERROR: Unrecognized Page!");
} }

View file

@ -127,4 +127,20 @@ impl Manager {
// Returning the password // Returning the password
return (success, selected_password); return (success, selected_password);
} }
pub fn password_list(&mut self) -> Vec<Password> {
// Result variable
let mut result: Vec<Password> = Vec::new();
// Going through all passwords and adding them to the list
for password in &self.passwords {
result.push(Password {
name: password.name.clone(),
user: password.user.clone(),
phrase: String::from("[REDACTED]")
});
}
// Giving back result
return result;
}
} }