//change the password public static void changePassword(int index, List <Account> listAcct) { Account acc = listAcct[index - 1]; Console.Write("new password: "); string newPassword = Console.ReadLine(); // PasswordTester class demonstration DateTime dateNow = DateTime.Now; PasswordTester pw = new PasswordTester(newPassword); acc.Password.Value = newPassword; acc.Password.StrengthText = pw.StrengthLabel; acc.Password.StrengthNum = pw.StrengthPercent; acc.Password.LastReset = dateNow.ToShortDateString(); }
//add the account public static void addAccount(JSchema schema, List <Account> lAccouts) { bool flagAddNew; do { flagAddNew = false; Account newAcc = new Account(); Console.WriteLine("\nPlease key-in values for the following fields...\n"); Console.Write("{0,-25}", "Description:"); newAcc.Description = Console.ReadLine();; Console.Write("{0,-25}", "User ID:"); newAcc.UserId = Console.ReadLine(); Console.Write("{0,-25}", "Password:"******"{0,-25}", "Login url:"); newAcc.LoginUrl = Console.ReadLine(); Console.Write("{0,-25}", "Account #:"); newAcc.AccountNum = Console.ReadLine(); string nAcc = JsonConvert.SerializeObject(newAcc); JObject JnewAcc = JObject.Parse(nAcc); //use schema to validate the Json data of the account that user added if (!JnewAcc.IsValid(schema)) { Console.WriteLine("ERROR: Invalid account information entered. Please try again."); flagAddNew = true; } else { lAccouts.Add(newAcc); string path = newAcc.Description + ".json"; using (File.Create(path)) { } using (StreamWriter sWriter = new StreamWriter(path)) { sWriter.WriteLine(nAcc); } } } while (flagAddNew);//end while }
static void Main(string[] args) { //display header Console.WriteLine("PASSWORD MANAGEMENT SYSTEM\n"); bool show = false; string path_json_data = RelativeToAbsolutePath("accountCollection.json"); string path_json_schema = RelativeToAbsolutePath("json-schema-password-manager.json"); do { Console.WriteLine("+--------------------------------------------------------------------+"); Console.WriteLine("| Account Entries |"); Console.WriteLine("+--------------------------------------------------------------------+"); Collection cltn = new Collection(); //check if JSON file exists if (!File.Exists(path_json_data)) { cltn.accCollection = new List <Account>(); } else { //if the JSON exists, try to read and display a list of existing accounts try { cltn = ReadJsonFileToCollection();//read json file } catch (IOException) { Console.WriteLine("ERROR: Cannot read from JSON file."); } } if (cltn.accCollection.Any())// if there is any existing account in collection { int seq = 1; foreach (Account acc in cltn.accCollection) { Console.WriteLine("| " + seq + $". {acc.description}"); seq++; } } Console.WriteLine("+--------------------------------------------------------------------+"); //display command instruction if (cltn.accCollection.Any()) // if there is any existing account in collection { // display this line Console.WriteLine("| Press # from above list to select an entry."); } Console.WriteLine("| Press A to add a new entry."); Console.WriteLine("| Press X to quit."); Console.WriteLine("+--------------------------------------------------------------------+\n"); Console.Write("Enter a command: "); string command = Console.ReadLine(); int commandNum = 0; string PDMCommand = ""; bool validPDM; bool empty; bool inputAgain; // Add new entry if (command.ToUpper() == "A") { Account acc = new Account(); do { Console.WriteLine("Please key-in values for the following fields...\n"); Console.Write("Description: "); acc.description = Console.ReadLine(); Console.Write("User ID: "); acc.userID = Console.ReadLine(); do { Console.Write("Password: "******"ERROR: The password should not be empty."); } } while (empty); acc.psWord.pwLastReset = DateTime.Now.ToShortDateString(); PasswordTester pwTester = new PasswordTester(acc.psWord.password); acc.psWord.pwStrengthText = pwTester.StrengthLabel; acc.psWord.pwStrengthNum = pwTester.StrengthPercent; Console.Write("Login url: "); acc.loginURL = Console.ReadLine(); if (acc.loginURL == "") { acc.loginURL = null;// if user does not provide login url, set the value to null to make it valid when validate with format URI } Console.Write("Account #: "); acc.accountNo = Console.ReadLine(); cltn.addAccount(acc); //write data to Json file, Read the file and validate against schema WriteDataToJsonFile(cltn); string json_data = File.ReadAllText(path_json_data); string json_schema = File.ReadAllText(path_json_schema); IList <string> messages; if (ValidateAccountData(json_data, json_schema, out messages)) // if validation is successful { show = true; //show main menu inputAgain = false; // don't ask for re-enter account info } else // unsuccessful validation against schema { Console.WriteLine("ERROR: Invalid account information entered. Please try again."); foreach (string msg in messages) { Console.WriteLine($"\t{msg}"); // output all error msg } if (cltn.accCollection.Any()) { cltn.deleteAccount(acc); // delete the account with invalid input } WriteDataToJsonFile(cltn); inputAgain = true; //ask for re-enter account info } } while (inputAgain); } //View selected entry else if (Int32.TryParse(command, out commandNum)) { try { Account selectedAccount = cltn.accCollection[commandNum - 1]; if (commandNum > 0 && commandNum <= cltn.accCollection.Count) { Console.WriteLine("+--------------------------------------------------------------------+"); Console.WriteLine("| " + commandNum + $". {selectedAccount.description}"); Console.WriteLine("+--------------------------------------------------------------------+"); Console.WriteLine($"| User ID: {selectedAccount.userID}"); Console.WriteLine($"| Password: {selectedAccount.psWord.password}"); Console.WriteLine($"| Password Strength: {selectedAccount.psWord.pwStrengthText} ({selectedAccount.psWord.pwStrengthNum}%)"); Console.WriteLine($"| Password Reset: {selectedAccount.psWord.pwLastReset}"); Console.WriteLine($"| Login url: {selectedAccount.loginURL}"); Console.WriteLine($"| Account #: {selectedAccount.accountNo}"); do { Console.WriteLine("+--------------------------------------------------------------------+"); Console.WriteLine("| Press P to change this password."); Console.WriteLine("| Press D to delete this entry."); Console.WriteLine("| Press M to return to main menu."); Console.WriteLine("+--------------------------------------------------------------------+"); Console.Write("Enter a command: "); PDMCommand = Console.ReadLine(); validPDM = PDMCommand.ToUpper() == "P" || PDMCommand.ToUpper() == "D" || PDMCommand.ToUpper() == "M"; if (!validPDM) { Console.WriteLine("ERROR: Incorrect command. Please try again!"); } } while (!validPDM); //Change Password if (PDMCommand.ToUpper() == "P") { do { Console.Write("New Password: "******"ERROR: The password should not be empty."); } } while(empty); PasswordTester pwTester = new PasswordTester(selectedAccount.psWord.password); selectedAccount.psWord.pwStrengthText = pwTester.StrengthLabel; selectedAccount.psWord.pwStrengthNum = pwTester.StrengthPercent; selectedAccount.psWord.pwLastReset = DateTime.Now.ToShortDateString(); show = true; //display main menu } //Delete selected entry else if (PDMCommand.ToUpper() == "D") { Console.Write("Delete? (Y/N): "); bool delete = Console.ReadKey().KeyChar == 'y'; Console.WriteLine(); if (delete) { cltn.deleteAccount(selectedAccount); } show = true; } else if (PDMCommand.ToUpper() == "M") { show = true; // go back to main menu } } } catch (Exception) { Console.WriteLine("Invalid account sequence in the list!"); show = true; } } //Exit program else if (command.ToUpper() == "X") { show = false; // exit program } else // wrong command will notify error { Console.WriteLine("ERROR: Incorrect command. Please try again!"); show = true; } WriteDataToJsonFile(cltn); } while (show); }
static void Main(string[] args) { Console.Write("PASSWORD MANAGER PROGRAM!"); // a string variable string json_data; string json_schema = ""; if (ReadFile(DATA_FILE, out json_data)) { // Create a collection to hold all items List <Account> acc_list = new List <Account>(); acc_list = ReadJsonFileToLib(); //Number of acc int numOfAcc = 0; //print Info numOfAcc = PrintInfo(acc_list); //Check command bool done = false; char cm = ' '; do { Console.Write("\n\tEnter a command: "); cm = Console.ReadKey().KeyChar; if (cm == 'm') { numOfAcc = PrintInfo(acc_list); } else { if (cm == 'a') { bool valid; Account acc = new Account(); do { Console.WriteLine("\n\nPlease enter value for the following field:\n"); do { Console.Write("Description: "); acc.Description = Console.ReadLine(); } while (string.IsNullOrEmpty(acc.Description)); do { Console.Write("User ID: "); acc.UserId = Console.ReadLine(); } while (string.IsNullOrEmpty(acc.UserId)); do { Console.Write("Password: "******"Login URL: "); acc.LoginUrl = Console.ReadLine(); Console.Write("Account #: "); acc.AccountNum = Console.ReadLine(); try { ReadFile(SCHEMA_FILE, out json_schema); } catch (Exception) { Console.WriteLine("\nERROR:\tUnable to read the schema file."); } // Validate the item object against the schema using the ValidateItem() method // and IF the object is invalid, repeat the user-input code above to repopulate the // object until it's valid valid = ValidateItem(acc, json_schema); if (!valid) { Console.WriteLine("\nERROR:\tItem data does not match the required format. Please try again.\n"); } } while (!valid); acc_list.Add(acc); numOfAcc = PrintInfo(acc_list); } else { if (Char.IsDigit(cm)) { temp = int.Parse(cm.ToString()); if (temp < 0 || temp > numOfAcc) { Console.WriteLine("\n\tInvalid input, try again!"); } else { printAccInfo(temp, acc_list); } } else { //Edit account if (cm == 'p') { if (temp != 0) { Console.Write("\n\tEnter new password: "******"\tPassword of account {temp} was changed!\n"); } else { Console.WriteLine("\n\tInvalid input, try again!"); } } else { if (cm == 'd') { if (temp != 0) { acc_list.RemoveAt(temp - 1); Console.WriteLine($"\n\tDeleted account number: {temp}. \n\tPress 'm' to see new account list."); } else { Console.WriteLine("\n\tInvalid input, try again!"); } } else { if (cm == 'x') { break; } else { Console.WriteLine("\n\tInvalid input, try again!"); } } } } } } } while (!done); //Write the account list to a file string json_all = JsonConvert.SerializeObject(acc_list); try { File.WriteAllText(DATA_FILE, json_all); Console.WriteLine($"\nYour account list has been written to {DATA_FILE}.\n"); } catch (IOException ex) { Console.WriteLine($"\n\nERROR: {ex.Message}.\n"); } } else { Console.WriteLine("\nERROR:\tUnable to read the data file."); } int PrintInfo(List <Account> acc_list) { int j = 0; //Give info to the console Console.WriteLine($"\n\n{decor}"); Console.WriteLine("\t\t\t\tACCOUNT ENTRIES"); Console.WriteLine(decor); foreach (Account acc in acc_list) { j++; Console.WriteLine($"\t\t {j}. {acc.Description}"); } Console.WriteLine(decor); Console.WriteLine("\t*Select a number from the above list to select an entry."); Console.WriteLine("\t*Press 'a' to add new entry."); Console.WriteLine("\t*Press 'x' to quit."); Console.WriteLine(decor); return(j); } void printAccInfo(int t, List <Account> acc_list) { Console.WriteLine($"\n{decor}"); Console.WriteLine($" {t}. {acc_list[t - 1].Description}"); Console.WriteLine(decor); Console.WriteLine($"User ID :\t{acc_list[t - 1].UserId} "); Console.WriteLine($"Password :\t{acc_list[t - 1].Password.Value} "); Console.WriteLine($"Password strength :\t{acc_list[t - 1].Password.StrengthText} ({acc_list[t - 1].Password.StrengthNum} %) "); Console.WriteLine($"Password Reset :\t{acc_list[t - 1].Password.LastReset} "); Console.WriteLine($"Login URL :\t{acc_list[t - 1].LoginUrl} "); Console.WriteLine(decor); Console.WriteLine("\t*Press 'p' to change this password."); Console.WriteLine("\t*Press 'd' to delete this entry."); Console.WriteLine("\t*Press 'm' to return to main menu."); Console.WriteLine(decor); } } // end Main()
static void Main(string[] args) { bool done = false; List <Account> accounts_list = new List <Account>(); //Read acocunts_schema.json file string json_schema; if (ReadFile(SCHEMA_FILE, out json_schema)) { //Read accounts in accounts_data.json file string accountsData; if (ReadFile(ACCOUNTS_FILE, out accountsData)) { try { accounts_list = JsonConvert.DeserializeObject <List <Account> >(accountsData); } catch (IOException) { Console.WriteLine("\nERROR: Can not read the JSON File\n"); } catch (ArgumentException) { Console.WriteLine("\nERROR: Can not convert the JSON data to a Library object.\n"); } } do { PrintHeader(accounts_list); //Bool variables to check for menu options pressed bool validEntryMainMenu = false, subMenuPressed = false; //Account index int accountListIndex; do { //If any option from the account submenu is pressed, get back to the main menu if (subMenuPressed) { validEntryMainMenu = true; continue; } //Check menu input string ch = Console.ReadLine().ToLower(); //Add another entry if (ch == "a") { Account newAccount; bool isValid; do { newAccount = new Account(); validEntryMainMenu = true; Console.WriteLine("\nPlease key-in values for the following fields: \n"); Console.Write("Description: "); newAccount.Description = Console.ReadLine(); Console.Write("User Id: "); newAccount.UserId = Console.ReadLine(); Password newUserPassword = new Password(); Console.Write("Password: "******"Login url: "); newAccount.LoginUrl = Console.ReadLine(); Console.Write("Account #: "); newAccount.AccountNum = Console.ReadLine(); //Validate account object with schema IList <string> messages; isValid = ValidateItem(newAccount, json_schema, out messages); if (!isValid) { Console.WriteLine("\nError: Invalid account information entered. Please try again."); // Report validation error messages foreach (string msg in messages) { Console.WriteLine($"{msg}"); } } } while (!isValid); accounts_list.Add(newAccount); } else if (ch == "x") { validEntryMainMenu = true; done = true; continue; } else if (int.TryParse(ch, out accountListIndex)) { bool validEntryAccountMenu = false; try { PrintAccountInfo(accounts_list[accountListIndex - 1], accountListIndex); } //Exception if index number written does not exist in account list catch (Exception ex) { Console.Write("\nAccount index does not exist! Please try another command: "); continue; } //Printing account sub menu Console.WriteLine("+---------------------------------------------------------------+"); Console.WriteLine("| Press P to change this password |"); Console.WriteLine("| Press D to delete this entry. |"); Console.WriteLine("| Press M to return to the main menu. |"); Console.WriteLine("+-------------------------------------------------------------- +"); Console.Write("\nEnter a command: "); do { string ch2 = Console.ReadLine().ToLower(); //Password change entry if (ch2 == "p") { validEntryAccountMenu = true; subMenuPressed = true; Console.Write("\nEnter New Password: "******"\nPassword changed!\n"); continue; } //Delete Entry else if (ch2 == "d") { validEntryAccountMenu = true; subMenuPressed = true; accounts_list.RemoveAt(accountListIndex - 1); Console.WriteLine("Account Deleted!\n"); } //Back to Main Menu else if (ch2 == "m") { validEntryAccountMenu = true; subMenuPressed = true; Console.WriteLine("\n*** Back To Main Menu ***\n"); continue; } //Command in account submenu was not valid else { Console.Write("\nCommand entered is not valid! Please try again: "); } } while (!validEntryAccountMenu); } //Command in main menu was not valid else { Console.Write("\nCommand entered is not valid! Please try again: "); } } while (!validEntryMainMenu); } while (!done); // Write the Account list to a file string json_all = JsonConvert.SerializeObject(accounts_list); try { File.WriteAllText(ACCOUNTS_FILE, json_all); Console.WriteLine($"\n\nYour shopping list has been written to {ACCOUNTS_FILE}.\n"); } catch (IOException ex) { Console.WriteLine($"\n\nERROR: {ex.Message}.\n"); } } else { Console.WriteLine("\nERROR: JSON Schema could not be found!\n"); } }// END MAIN
//Main Method static void Main(string[] args) { //Start of the Program Console.WriteLine("\n PASSWORD-MANAGER PREPARED BY SANDY - Copyright 2019\n"); //Global Variables string temp; int value; bool restart = false; //bools used in while loops string Schema; /* * Note: It creates the JSON File in teh Debug Folder */ var fileInfo = new FileInfo("CompanyInfo.json"); //If it doesn't exist create new one or if it is empty proceed from here if (!fileInfo.Exists || fileInfo.Length == 0) { /* * Introduction to the program */ Console.WriteLine("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); Console.WriteLine("| Account Entries |"); Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); Console.WriteLine("\nEMPTY! Please add Some Accounts"); var myFile = File.Create("CompanyInfo.json"); //Create if empty myFile.Close(); Console.WriteLine("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); Console.WriteLine("| Menu |"); Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); Console.Write("|Press A to add the Account |"); Console.Write("\n|Press Q to Quit the Application |"); Console.WriteLine("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); bool f = false; //To check for the valid input while (f == false) { Console.Write("Enter Here: "); temp = Console.ReadLine(); f = true; if (temp.Equals("a") || temp.Equals("A")) //If the user wants to add the account information { CompanyInventory companyDb = new CompanyInventory(); //New company Database object, which will store the Accounts bool complete; //To add as many accounts in the file do { Company comp = new Company(); // New Company object Console.WriteLine("\n\nPlease enter the following information...\n"); bool okay = false; Console.Write("Decription: "); while (okay == false) { okay = true; comp.name = Console.ReadLine(); if (comp.name == "") { //Validation Console.WriteLine("\nDescription is required!!\n"); Console.Write("Description: "); okay = false; } } Account acc = new Account(); Console.Write("UserID: "); bool flag = false; while (flag == false) { flag = true; acc.userId = Console.ReadLine(); if (acc.userId == "") { //Validation Console.WriteLine("\nUserID is required!!\n"); Console.Write("UserID:"); flag = false; } } Password pass = new Password(); //New Password Object to store the password properties bool good = false; while (good == false) { good = true; Console.Write("Password: "******"ERROR: Invalid password format"); good = false; } catch (InvalidOperationException) { Console.WriteLine("Password is required!!!"); good = false; } } Console.Write("LoginUrl: "); acc.loginUrl = Console.ReadLine(); //string pattern = "(\\http[s] ?:\\/\\/)?([^\\/\\s] +\\/)(.*)"; Console.Write("Account#: "); acc.AccountNum = Console.ReadLine(); DateTime dateNow = DateTime.Now; pass.LastReset = dateNow.ToShortDateString(); acc.addPass(pass); comp.addAcc(acc); companyDb.addComp(comp); Console.Write("\nAdd another Account? (y/n): "); complete = Console.ReadKey().KeyChar != 'y'; if (complete.Equals(true)) { Console.ForegroundColor = ConsoleColor.Black; Console.BackgroundColor = ConsoleColor.White; Console.WriteLine("\n***Please restart the application***\n"); Console.ForegroundColor = ConsoleColor.White; Console.BackgroundColor = ConsoleColor.Black; } } while (!complete); writeCompToJsonFile(companyDb); } else if (temp.Equals("q") || temp.Equals("Q")) { Console.WriteLine("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); Console.WriteLine("| Thank you for using my Application! |"); Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); System.Environment.Exit(1); } else { Console.WriteLine("***Please enter Valid Input***"); f = false; } } } else { while (restart == false) //used to repeat the process if user make mistake { restart.Equals(true); CompanyInventory readDb = new CompanyInventory(); //New Company DB to store the info readDb = ReadJsonFile(); //Intro Console.ForegroundColor = ConsoleColor.White; Console.BackgroundColor = ConsoleColor.Black; Console.WriteLine("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); Console.WriteLine("| Account Entries |"); Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); if (readDb.db.Count == 0) { Console.ForegroundColor = ConsoleColor.Black; Console.BackgroundColor = ConsoleColor.White; Console.WriteLine("\nEMPTY! Please add Some Accounts\n"); Console.ForegroundColor = ConsoleColor.White; Console.BackgroundColor = ConsoleColor.Black; } int num = 1; //If data exists, Show the Account Decription (Name) foreach (Company company in readDb.db) { Console.Write((num) + $". {company.name}"); Console.WriteLine(); num = num + 1; } Console.WriteLine("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); Console.WriteLine("| Menu |"); Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); Console.Write("|Press A to add the Account |"); Console.WriteLine("\n|Press # corresponding to the entry to read or update the Account Info |"); Console.WriteLine("|Press Q to Quit the Application |"); Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); Console.Write("Enter Here: "); temp = Console.ReadLine(); if (int.TryParse(temp, out value) || temp.Equals("Q") || temp.Equals("q") || temp.Equals("a") || temp.Equals("A")) { } else { //ERROR Console.ForegroundColor = ConsoleColor.Black; Console.BackgroundColor = ConsoleColor.White; Console.WriteLine("\n***Please enter valid input!!***\n"); Console.ForegroundColor = ConsoleColor.White; Console.BackgroundColor = ConsoleColor.Black; } //If user wants to add if (temp.Equals("a") || temp.Equals("A")) { bool complete2; do { Company comp = new Company(); Console.WriteLine("\n\nPlease enter the following information...\n"); bool okay = false; bool flag = false; bool good = false; Console.Write("Decription: "); while (okay == false) { okay = true; comp.name = Console.ReadLine(); if (comp.name == "") { Console.ForegroundColor = ConsoleColor.Black; Console.BackgroundColor = ConsoleColor.White; Console.WriteLine("\n***Description is required!!***\n"); Console.ForegroundColor = ConsoleColor.White; Console.BackgroundColor = ConsoleColor.Black; Console.Write("Description: "); okay = false; } } Account acc = new Account(); Console.Write("UserID: "); while (flag == false) { flag = true; acc.userId = Console.ReadLine(); if (acc.userId == "") { //ERROR Message Console.ForegroundColor = ConsoleColor.Black; Console.BackgroundColor = ConsoleColor.White; Console.WriteLine("\nUserID is required!!\n"); Console.ForegroundColor = ConsoleColor.White; Console.BackgroundColor = ConsoleColor.Black; Console.Write("UserID:"); flag = false; } } Password pass = new Password(); while (good == false) { good = true; Console.Write("Password: "******"\nERROR: Invalid password format\n"); Console.ForegroundColor = ConsoleColor.White; Console.BackgroundColor = ConsoleColor.Black; good = false; } catch (InvalidOperationException) { //ERROR Message Console.ForegroundColor = ConsoleColor.White; Console.BackgroundColor = ConsoleColor.Black; Console.WriteLine("\nPassword is required!!!"); Console.ForegroundColor = ConsoleColor.Black; Console.BackgroundColor = ConsoleColor.White; good = false; } } Console.Write("LoginUrl: "); acc.loginUrl = Console.ReadLine(); Console.Write("Account#: "); acc.AccountNum = Console.ReadLine(); DateTime dateNow = DateTime.Now; pass.LastReset = dateNow.ToShortDateString(); acc.addPass(pass); comp.addAcc(acc); readDb.addComp(comp); Console.Write("\nAdd another item? (y/n): "); complete2 = Console.ReadKey().KeyChar != 'y'; } while (!complete2); //Write the entered data to a JSON File writeCompToJsonFile(readDb); restart.Equals(false); } //if number(int) is entered, It will try to parse- If successful then will show the output and if not displays the error message else if (int.TryParse(temp, out value)) { int EntryNum = value - 1; try { //Accessing the information based on the user input Console.WriteLine("\n" + value + $". {readDb.db[EntryNum].name}"); Console.WriteLine(); foreach (Account account in readDb.db[EntryNum].Inventory) { string readpassword = ""; string readLabel = ""; ushort readNum = 0; string readDate = ""; Console.WriteLine($"UserID: {account.userId}"); foreach (Password password in readDb.db[EntryNum].Inventory[0].passDb) { readpassword = password.value; readLabel = password.StrengthText; readNum = password.StrengthNum; readDate = password.LastReset; } Console.WriteLine($"Password: {readpassword}"); Console.WriteLine($"Password Strength: {readLabel} ({readNum})%"); Console.WriteLine($"Password Reset Date: {readDate}"); Console.WriteLine($"LoginUrl: {account.loginUrl}"); Console.WriteLine($"Account #: {account.AccountNum}"); } //Second Menu Console.WriteLine("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); Console.WriteLine("| Press M to for Main Menu |"); Console.WriteLine("| Press P to update the password |"); Console.WriteLine("| Press D to delete the Account Info |"); Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); Console.Write("Enter Here: "); temp = Console.ReadLine(); //For Main Menu if (temp.Equals("M") || temp.Equals("m")) { restart.Equals(false); } //For Password Change Request else if (temp.Equals("P") || temp.Equals("p")) { Console.Write("\nNew Password: "******"***Password Changed***"); Console.ForegroundColor = ConsoleColor.Black; Console.BackgroundColor = ConsoleColor.White; restart.Equals(false); } //To Delete the Account Information else if (temp.Equals("D") || temp.Equals("d")) { try { Console.Write("Delete?(Y/N): "); temp = Console.ReadLine(); if (temp.Equals("Y") || temp.Equals("y")) { readDb.db.RemoveAt(EntryNum); writeCompToJsonFile(readDb); restart.Equals(false); } else if (temp.Equals("N") || temp.Equals("n")) { restart.Equals(false); } else { throw new IndexOutOfRangeException(); //Throws exception to handle the wrong input } } catch (Exception e) //Catches all the exceptions { Console.ForegroundColor = ConsoleColor.White; Console.BackgroundColor = ConsoleColor.Black; Console.WriteLine("\n***Please enter a valid input!!***\n"); Console.ForegroundColor = ConsoleColor.Black; Console.BackgroundColor = ConsoleColor.White; } } else { throw new IndexOutOfRangeException();//Throws exception to handle the wrong input } } catch (Exception e) //Catches all the exceptions { Console.ForegroundColor = ConsoleColor.White; Console.BackgroundColor = ConsoleColor.Black; Console.WriteLine("\n***Please enter valid number!!***\n"); Console.ForegroundColor = ConsoleColor.Black; Console.BackgroundColor = ConsoleColor.White; restart.Equals(false); } } //IF wants to quit else if (temp.Equals("q") || temp.Equals("Q")) { Console.WriteLine("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); Console.WriteLine("| Thank you for using my Application! |"); Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); System.Environment.Exit(1); } } } }