|
-
Aug 7th, 2004, 03:00 PM
#1
Thread Starter
Junior Member
Hiding console input
I'm working on a console application where you have to enter in a username and password for a database and I was hoping to make it so when the user enters their password in, it isn't visible in the console window.
I think I can figure out how to do it but the problem is I'm not sure how to capture each and every individual key. So then if I could do that, if the key was something other than enter, it would add it to a string and then write back: \b\0\b to erase it.
So my question is, how can I capture each key?
-
Aug 10th, 2004, 08:34 PM
#2
Frenzied Member
Code:
using System;
using System.Text;
class a
{
Console.Write("Input a password: ");
StringBuilder sb = new StringBuilder();
while (true)
{
ConsoleKeyInfo cki = Console.ReadKey(true);
if (cki.Key == ConsoleKey.Enter)
{
Console.WriteLine();
break;
}
if (cki.Key == ConsoleKey.BackSpace)
{
if (sb.Length > 0)
{
Console.Write("\b\0\b");
sb.Length--;
}
continue;
}
Console.Write('*');
sb.Append(cki.KeyChar);
}
Console.WriteLine("Your password is: {0}", sb.ToString());
}
that may help you.
-
Aug 13th, 2004, 11:47 AM
#3
Frenzied Member
I've seen that code snippet floating around the WWW but I think you need Whidbey to use it...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|