Deveel.Readline.ReadPassword C# (CSharp) Méthode

ReadPassword() public static méthode

public static ReadPassword ( string prompt ) : string
prompt string
Résultat string
        public static string ReadPassword(string prompt)
        {
            // Output the prompt.
            if (prompt != null)
                Console.Write(prompt);

            Stack pass = new Stack();

            for (ConsoleKeyInfo consKeyInfo = Console.ReadKey(true);
              consKeyInfo.Key != ConsoleKey.Enter; consKeyInfo = Console.ReadKey(true)) {
                if (consKeyInfo.Key == ConsoleKey.Backspace) {
                    try {
                        Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop);
                        Console.Write(" ");
                        Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop);
                        pass.Pop();
                    } catch (InvalidOperationException) {
                        Console.SetCursorPosition(Console.CursorLeft + 1, Console.CursorTop);
                    }
                } else {
                    Console.Write("*");
                    pass.Push(consKeyInfo.KeyChar.ToString());
                }
            }
            object[] chars = pass.ToArray();
            string[] password = new string[chars.Length];
            Array.Copy(chars, password, chars.Length);
            Array.Reverse(password);
            return string.Join(string.Empty, password);
        }