diff --git a/src/interface.rs b/src/interface.rs index c9a301b..c5585ca 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -60,10 +60,11 @@ pub fn int_welcome(username: &String) -> String { println!("\n - {} RUSTYPASS {} - ", COLOR_YELLOW, COLOR_RESET); println!("Welcome, {}{}{}!", COLOR_CYAN, username, COLOR_RESET); println!("Please select one of the following options: "); - println!("\n{}1{}) View a Password", COLOR_GREEN, COLOR_RESET); - println!("{}2{}) Create a Password", COLOR_GREEN, COLOR_RESET); - println!("{}3{}) Generate a Password", COLOR_GREEN, COLOR_RESET); - println!("{}4{}) Quit", COLOR_GREEN, COLOR_RESET); + println!("\n{}1{}) List passwords", COLOR_GREEN, COLOR_RESET); + println!("{}2{}) View a Password", COLOR_GREEN, COLOR_RESET); + println!("{}3{}) Create a Password", 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"); // 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!("Passphrase:\t{}{}{}", COLOR_GREEN, pass_obj.phrase, COLOR_RESET); println!(""); +} +pub fn int_list(manager: &mut manager::Manager){ + // Getting password names + let passwords: Vec = 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); + } } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index a85e500..6d1a2db 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,19 +35,21 @@ fn stage_manager(auth_profile: &mut auth::Auth) { println!("\n"); // Deciding what page we are on - if page == "4" { + if page == "5" { println!("Goodbye, {}{}{}!", interface::COLOR_CYAN, auth_profile.username, interface::COLOR_RESET); break; - } else if page == "3" { + } else if page == "4" { let (pass_len, pass_num, pass_spe) = interface::int_gen(); 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); - } else if page == "2" { + } else if page == "3" { let (pass_name, pass_user, pass_phrase) = interface::int_create(); manager.password_create(pass_name.clone(), pass_user, pass_phrase); println!("\nSuccessfully added {}{}{}!", interface::COLOR_GREEN, pass_name, interface::COLOR_RESET); - } else if page == "1" { + } else if page == "2" { interface::int_view(&mut manager); + } else if page == "1" { + interface::int_list(&mut manager); } else { println!("ERROR: Unrecognized Page!"); } diff --git a/src/manager.rs b/src/manager.rs index b9b2981..b870168 100644 --- a/src/manager.rs +++ b/src/manager.rs @@ -127,4 +127,20 @@ impl Manager { // Returning the password return (success, selected_password); } + pub fn password_list(&mut self) -> Vec { + // Result variable + let mut result: Vec = 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; + } } \ No newline at end of file