Added password obfuscation while typing

Each character of the password is replaced by a star while typing
+ Fixed an old typo for "Handshake successfull" (ss -> cc).
This commit is contained in:
ORelio 2013-08-23 10:48:26 +02:00
parent f26ff323fd
commit f7835e7f60
3 changed files with 47 additions and 6 deletions

View file

@ -24,6 +24,48 @@ namespace MinecraftClient
private static bool writing_lock = false; private static bool writing_lock = false;
#region Read User Input #region Read User Input
public static string ReadPassword()
{
string password = "";
ConsoleKeyInfo k = new ConsoleKeyInfo();
while (k.Key != ConsoleKey.Enter)
{
k = Console.ReadKey(true);
switch (k.Key)
{
case ConsoleKey.Enter:
Console.Write('\n');
return password;
case ConsoleKey.Backspace:
if (password.Length > 0)
{
Console.Write("\b \b");
password = password.Substring(0, password.Length - 1);
}
break;
case ConsoleKey.Escape:
case ConsoleKey.LeftArrow:
case ConsoleKey.RightArrow:
case ConsoleKey.Home:
case ConsoleKey.End:
case ConsoleKey.Delete:
case ConsoleKey.Oem6:
case ConsoleKey.DownArrow:
case ConsoleKey.UpArrow:
case ConsoleKey.Tab:
break;
default:
Console.Write('*');
password += k.KeyChar;
break;
}
}
return password;
}
public static string ReadLine() public static string ReadLine()
{ {
if (basicIO) { return Console.ReadLine(); } if (basicIO) { return Console.ReadLine(); }

View file

@ -656,7 +656,7 @@ namespace MinecraftClient
var PublicServerkey = Crypto.GenerateRSAPublicKey(Serverkey_RAW); var PublicServerkey = Crypto.GenerateRSAPublicKey(Serverkey_RAW);
var SecretKey = Crypto.GenerateAESPrivateKey(); var SecretKey = Crypto.GenerateAESPrivateKey();
Console.ForegroundColor = ConsoleColor.DarkGray; Console.ForegroundColor = ConsoleColor.DarkGray;
Console.WriteLine("Handshake sussessful. (Server ID: " + serverID + ')'); Console.WriteLine("Handshake successful. (Server ID: " + serverID + ')');
Console.ForegroundColor = ConsoleColor.Gray; Console.ForegroundColor = ConsoleColor.Gray;
return StartEncryption(username, sessionID, token, serverID, PublicServerkey, SecretKey); return StartEncryption(username, sessionID, token, serverID, PublicServerkey, SecretKey);
} }

View file

@ -157,13 +157,12 @@ namespace MinecraftClient
if (Settings.Password == "") if (Settings.Password == "")
{ {
Console.Write(ConsoleIO.basicIO ? "Please type the password for " + Settings.Login + ".\n" : "Password : "); Console.Write(ConsoleIO.basicIO ? "Please type the password for " + Settings.Login + ".\n" : "Password : ");
Settings.Password = Console.ReadLine(); Settings.Password = ConsoleIO.basicIO ? Console.ReadLine() : ConsoleIO.ReadPassword();
if (Settings.Password == "") { Settings.Password = "-"; }
if (!ConsoleIO.basicIO) if (!ConsoleIO.basicIO)
{ {
//Hide the password //Hide password length
Console.CursorTop--; Console.CursorTop--; Console.Write("Password : <******>");
Console.Write("Password : <******>");
for (int i = 19; i < Console.BufferWidth; i++) { Console.Write(' '); } for (int i = 19; i < Console.BufferWidth; i++) { Console.Write(' '); }
} }
} }