Created
October 1, 2017 03:22
-
-
Save CristianoRC/ab09c13b589301fb40db9e1fe551e2bc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public static string LerSenha() | |
{ | |
StringBuilder pw = new StringBuilder(); | |
bool caracterApagado = false; | |
while (true) | |
{ | |
ConsoleKeyInfo cki = Console.ReadKey(true); | |
if (cki.Key == ConsoleKey.Enter) | |
{ | |
Console.WriteLine(); | |
break; | |
} | |
if (deletarTexto(cki)) | |
{ | |
if (pw.Length != 0) | |
{ | |
Console.Write("\b \b"); | |
pw.Length--; | |
caracterApagado = true; | |
} | |
} | |
else | |
{ | |
caracterApagado = false; | |
} | |
if (!caracterApagado && verificarCaracterValido(cki)) | |
{ | |
Console.Write('•'); | |
pw.Append(cki.KeyChar); | |
} | |
} | |
return pw.ToString(); | |
} | |
private static bool verificarCaracterValido(ConsoleKeyInfo tecla) | |
{ | |
if (char.IsLetterOrDigit(tecla.KeyChar) || char.IsPunctuation(tecla.KeyChar) || | |
char.IsSymbol(tecla.KeyChar)) | |
{ | |
return true; | |
} | |
else | |
{ | |
return false; | |
} | |
} | |
private static bool deletarTexto(ConsoleKeyInfo tecla) | |
{ | |
if (tecla.Key == ConsoleKey.Backspace || tecla.Key == ConsoleKey.Delete) | |
return true; | |
else | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment