Created
January 22, 2011 21:46
-
-
Save OrigamiTech/791515 to your computer and use it in GitHub Desktop.
Function to get password input from a CLI without displaying the password.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static string getPassword() | |
{ | |
string Pass = ""; | |
char c = Console.ReadKey(true).KeyChar; | |
while (c != (char)0x0D) | |
{ | |
if (c == 0x08) | |
{ | |
if (Pass.Length > 0) | |
{ | |
Pass = Pass.Substring(0, Pass.Length - 1); | |
Console.CursorLeft--; | |
Console.Write(" "); | |
Console.CursorLeft--; | |
} | |
} | |
else | |
{ | |
Pass += c; | |
Console.Write("*"); | |
} | |
c = Console.ReadKey(true).KeyChar; | |
} | |
Console.WriteLine(""); | |
return Pass; | |
} |
doesn't repeat/until need begin/end blocks?
I guess not
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
God dammit there's no way to get the current row so I have to set y all the time. :<