Exemplo n.º 1
0
        public static string Run()
        {
            var dialog = new PasswordDialog();

            if (dialog.ShowDialog() != true)
            {
                throw new Exception("Password is required.");
            }
            return(dialog.password.Password);
        }
Exemplo n.º 2
0
        static void SetupPassword()
        {
            if (ResourceReader.Config.Password == null)
            {
                return;
            }

            if (Native.GetConsoleWindow() == IntPtr.Zero)
            {
                Resource.Password = PasswordDialog.Run();
                return;
            }

            Console.Write("Password: "******"";

            while (true)
            {
                var key = Console.ReadKey(true);
                if (key.Key == ConsoleKey.Backspace)
                {
                    if (password.Length > 0)
                    {
                        password = password.Remove(password.Length - 1);
                        Console.Write("\b \b");
                    }
                }
                else if (key.Key == ConsoleKey.Enter)
                {
                    if (password.Length > 0)
                    {
                        Console.WriteLine();
                        break;
                    }
                }
                else
                {
                    Console.Write("*");
                    password += key.KeyChar;
                }
            }

            Resource.Password = password;
        }