От: | Odi$$ey | http://malgarr.blogspot.com/ | |
Дата: | 07.12.07 04:21 | ||
Оценка: | |||
#Имя: | FAQ.dotnet.console.EnterPassword |
string _password;
static bool EnterPassword()
{
Console.Write("password: ");
_password="";
while(true)
{
ConsoleKeyInfo cki = Console.ReadKey(true);
if(cki.Key == ConsoleKey.Enter)
{
Console.WriteLine();
return true;
}
else
{
if(cki.Key == ConsoleKey.Escape)
{
_password = "";
return false;
}
else
{
if(Char.IsLetterOrDigit(cki.KeyChar) || Char.IsSymbol(cki.KeyChar))
{
_password+=cki.KeyChar;
Console.Write("*");
}
else
{
if(cki.Key == ConsoleKey.Backspace)
{
if(_password.Length > 0)
{
ReplaceEntry(" ", Console.CursorLeft - 1, Console.CursorTop);
_password = _password.Remove(_password.Length - 1);
}
}
else
{
Debug.Assert(false, "Этот случай невозможен! ");
}
}
}
}
}
}