private void ChangeMasterPasswordCommand(List <Shell.ParseResult> result) { if (repository == null) { Console.WriteLine("Password repository has not been opened."); return; } if (!CheckSaveChanges()) { Console.WriteLine("Aborted."); return; } var cr = new ConsoleReader(); cr.Prefix = "Current Master Password: "******"Access denied."); return; } cr.Prefix = "New Master Password: "******"Aborted."); return; } while (true) { cr.Prefix = "Confirm New Master Password: "******"Aborted."); return; } if (confirm.IsEqualTo(newrepositoryPassword)) { break; } Console.WriteLine("Passwords do not match."); } if (AskYesNoQuestion("Do you want to change the master password?") == Answer.Yes) { repository.ChangeMasterPassword(repositoryFileName, keyDirectory, newrepositoryPassword); repositoryPassword = newrepositoryPassword; Console.WriteLine("Master password changed."); } }
private void EditAccountCommand(List <Shell.ParseResult> result) { if (repository == null) { Console.WriteLine("Password repository has not been opened."); return; } if (result.Count < 2) { Console.WriteLine("Missing <account> argument."); return; } var pwditem = FindAccount(result[1].Input); if (pwditem != null) { var cr = new ConsoleReader(); cr.Prefix = "Name: "; string newname; while (true) { newname = cr.Read(pwditem.Name); if (newname == pwditem.Name || FindAccount(newname) == null) { break; } Console.WriteLine("The account already exists."); } cr.Prefix = "URL: "; var url = cr.Read(pwditem.Url); cr.Prefix = "Login: "******"Password: "******"Description: "; var desc = cr.Read(pwditem.Description); if (AskYesNoQuestion("Do you want to update the account?") == Answer.Yes) { if (pwd.Length > 0) { pwditem.SecurePassword = pwd; } if (pwditem.Name != newname) { pwditem.Name = newname; } pwditem.Url = url; pwditem.Login = login; pwditem.Description = desc; repository.Update(pwditem); Console.WriteLine("Account updated."); } } }
private void AddAccountCommand(List <Shell.ParseResult> result) { if (repository == null) { Console.WriteLine("Password repository has not been opened."); return; } var cr = new ConsoleReader(); cr.Prefix = "Name: "; string name; while (true) { name = cr.Read(); if (FindAccount(name) == null) { break; } Console.WriteLine("The account already exists."); } cr.Prefix = "URL: "; var url = cr.Read(); cr.Prefix = "Login: "******"Password: "******"Description: "; var desc = cr.Read(); if (AskYesNoQuestion("Do you want to add the account?") == Answer.Yes) { var pwditem = new Password { Name = name, Description = desc, Url = url, Login = login, SecurePassword = pwd }; repository.Add(pwditem); Console.WriteLine("Account added."); } }
private void OpenRepositoryCommand(List <Shell.ParseResult> result) { if (result.Count < 2) { Console.WriteLine("Missing <file> argument."); return; } if (!File.Exists(result[1].Input)) { Console.WriteLine("Password repository file does not exist."); return; } if (repository != null) { Console.WriteLine("Repository has not been closed."); return; } repositoryFileName = Path.GetFullPath(result[1].Input); if (result.Count > 2) { keyDirectory = Path.GetFullPath(result[2].Input); if (!Directory.Exists(keyDirectory)) { Console.WriteLine("Key directory does not exist."); return; } } else { keyDirectory = Path.GetDirectoryName(repositoryFileName); } var cs = new ConsoleReader(); cs.Prefix = "Master Password: "******"Repository opened."); } catch { Console.WriteLine("Access denied."); } }
private void NewRepositoryCommand(List <Shell.ParseResult> result) { if (result.Count < 2) { Console.WriteLine("Missing <file> argument."); return; } if (File.Exists(result[1].Input)) { Console.WriteLine("Password repository file already exists."); return; } if (repository != null) { Console.WriteLine("Repository has not been closed."); return; } repositoryFileName = Path.GetFullPath(result[1].Input); if (result.Count > 2) { keyDirectory = Path.GetFullPath(result[2].Input); if (!Directory.Exists(keyDirectory)) { Console.WriteLine("Key directory does not exist."); return; } } else { keyDirectory = Path.GetDirectoryName(repositoryFileName); } var cr = new ConsoleReader(); cr.Prefix = "Name: "; var name = cr.Read(Path.GetFileNameWithoutExtension(repositoryFileName)); cr.Prefix = "Description: "; var desc = cr.Read(); cr.Prefix = "Master Password: "******"Aborted."); return; } while (true) { cr.Prefix = "Confirm Master Password: "******"Aborted."); return; } if (confirm.IsEqualTo(repositoryPassword)) { break; } Console.WriteLine("Passwords do not match."); } if (AskYesNoQuestion("Do you want to create the repository?") == Answer.Yes) { repository = new PasswordRepository(); repository.Name = name; repository.Description = desc; repository.Save(repositoryFileName, keyDirectory, repositoryPassword); Console.WriteLine("Repository created."); } }