static void RetrievePassword() { string name = Prompt("Service name"); if (!List.Contains(name)) { Console.WriteLine("No such service."); } else { string password = List.Retrieve(name); Utilities.PrintColored("Password for %a{0}%7 is ", name); int pass_x = Console.CursorLeft; int pass_y = Console.CursorTop; Utilities.PrintColoredLine("%c{0}%7.", password); Utilities.SetClipboard(password); Console.WriteLine("Copied password to clipboard."); Console.Write("Auto-clearing in {0} seconds...", AutoClearDelay / 1000); int progress_x = Console.CursorLeft; int progress_y = Console.CursorTop; Console.WriteLine(); Task.Factory.StartNew( delegate { ActionTrigger.Reset(); bool result = ActionTrigger.WaitOne(AutoClearDelay); if (!result) { int temp_x = Console.CursorLeft; int temp_y = Console.CursorTop; Console.SetCursorPosition(pass_x, pass_y); Utilities.PrintColored("%c" + new string('█', password.Length) + "%7"); Console.SetCursorPosition(progress_x, progress_y); Console.Write("cleared."); Console.SetCursorPosition(temp_x, temp_y); } }); } }
static void GeneratePassword() { string name = Prompt("Service name"); while (List.Contains(name)) { if (!PromptConfirm("A password with that name already exists. Overwrite?")) { name = Prompt("Service name"); } else { break; } } string len = Prompt("Password length", "16"); string chars = Prompt("Characters to use", "lusd"); Dictionary <char, Characters> mappings = new Dictionary <char, Characters>() { { 'l', Characters.Letters }, { 'u', Characters.LettersUppercase }, { 's', Characters.SymbolsBasic }, { 'd', Characters.Numbers }, { 'a', Characters.SymbolsAdvanced } }; int length = int.Parse(len); Characters c = (Characters)0; foreach (var pair in mappings) { if (chars.Contains(pair.Key)) { c |= pair.Value; } } string password = List.Generate(name, new PasswordGenerator() { Characters = c, Length = length }); Utilities.PrintColored("Password for %a{0}%7 is ", name); int pass_x = Console.CursorLeft; int pass_y = Console.CursorTop; Utilities.PrintColoredLine("%c{0}%7.", password); Utilities.SetClipboard(password); Console.WriteLine("Copied password to clipboard."); Console.Write("Auto-clearing in {0} seconds...", AutoClearDelay / 1000); int progress_x = Console.CursorLeft; int progress_y = Console.CursorTop; Console.WriteLine(); Task.Factory.StartNew( delegate { ActionTrigger.Reset(); bool result = ActionTrigger.WaitOne(AutoClearDelay); if (!result) { int temp_x = Console.CursorLeft; int temp_y = Console.CursorTop; Console.SetCursorPosition(pass_x, pass_y); Utilities.PrintColored("%c" + new string('█', length) + "%7"); Console.SetCursorPosition(progress_x, progress_y); Console.Write("cleared."); Console.SetCursorPosition(temp_x, temp_y); } }); Save(); }