Encrypted input from user

  • Thread starter Thread starter gopal
  • Start date Start date
G

gopal

Hi,

I am developing a console application and i would like to get userinput
for

Database User & Password.

The Password should be input as **********

Please can some help me out on this?

Thanks & Regards
JP
 
Heres a simple way of doing it:

static string ReadLineButStarInput()
{
byte star = ASCIIEncoding.ASCII.GetBytes("*")[0];
ConsoleKeyInfo key = Console.ReadKey();
string input = "";

while (key.Key != ConsoleKey.Enter)
{
input += key.KeyChar;

Console.CursorLeft -= 1;
Console.OpenStandardOutput().WriteByte(star);
key = Console.ReadKey();

}
return input;

}

HTH


Ciaran O'Donnell
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top