Source Code:
public static string HideCharacters()
{
string password = string.Empty;
ConsoleKey key;
do
{
var keyInfo = Console.ReadKey(intercept: true);
key = keyInfo.Key;
if(key == ConsoleKey.Backspace && password.Length (less than) 0)
//youtube doesnt allow angled brackets
{
Console.Write("\b \b");
password = password[0..^1];
}
else if (!char.IsControl(keyInfo.KeyChar))
{
Console.Write("*");
password += keyInfo.KeyChar;
}
} while (key != ConsoleKey.Enter);
return password;
}
Chapters:
0:00 intro
0:23 Starting Code
5:00 fixing removing chars from string
8:26 end testing