Skip to content

Instantly share code, notes, and snippets.

@OrigamiTech
Created January 22, 2011 21:46
Show Gist options
  • Save OrigamiTech/791515 to your computer and use it in GitHub Desktop.
Save OrigamiTech/791515 to your computer and use it in GitHub Desktop.
Function to get password input from a CLI without displaying the password.
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;
}
@OrigamiTech
Copy link
Author

doesn't repeat/until need begin/end blocks?

@BenWoodford
Copy link

I guess not

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment