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!("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
@ -178,3 +179,13 @@ pub fn int_view(manager: &mut manager::Manager) {
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> = 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");
// 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!");
}

View file

@ -127,4 +127,20 @@ impl Manager {
// Returning the 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;
}
}