public static PrintColoredLine ( string message ) : void | ||
message | string | The message to print |
return | void |
static void AddPassword() { string name = Prompt("Enter a service name"); while (List.Contains(name)) { if (!PromptConfirm("A password with that name already exists. Overwrite?")) { name = Prompt("Enter a service name"); } else { break; } } string password = ""; while (true) { password = DiscreetPrompt("Password"); if (DiscreetPrompt("Confirm password") != password) { Console.WriteLine("Confirmation doesn't match password. Try again."); } else { break; } } List.Add(name, password); Utilities.PrintColoredLine("Added password for %a{0}%7.", name); }
static void InvokeAction() { string str = Console.ReadKey(true).KeyChar.ToString(); int selection = -1; if (!int.TryParse(str, out selection)) { return; } if (selection < 1 || selection > Actions.Count) { return; } ActionTrigger.Set(); Console.Clear(); var pair = GetAction(selection); Utilities.PrintColoredLine("Selected %f{0}%7.", pair.Key); try { pair.Value(); } catch (Exception ex) { Console.WriteLine(ex); } }
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 ListPasswords() { foreach (var entry in List.Passwords) { Utilities.PrintColoredLine("Name: %a{0}%7, password: %c{1}", entry.Name, entry.Password); } for (int i = 5; i > 0; i--) { if (i != 5) { Console.CursorTop--; } Console.WriteLine("Clearing in {0}...", i); Thread.Sleep(1000); } Console.Clear(); }
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(); }