By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,158 Members | 917 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,158 IT Pros & Developers. It's quick & easy.

safe "prompt for password" in console application

P: n/a
hi,

i'm writing a console application and i would like to be able to safely
retrive password from the user, so noone can see how it is being typed.
consider this scenario:
Console.Write("Enter password:");
string pass = Console.ReadLine()

when this is called and user types, his passsword is displayed on the
screen. i would like to avoid that, and do not print any characters or
eventually print only '*' char for each user typed char. i thought i
could use Console.Read() in a loop, but i can't make it work the way i
want. it seems that Console.Read() works almost the same as
Console.ReadLine() - it waits until user types what he needs and hits
[enter] and then starts reading char by char.

i know i'm missing something...
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Check this article out. It will help you, dont know if this is the "correct"
way to do it but it does the trick.

http://www.codeproject.com/dotnet/Co...swordInput.asp

--
Best regards Björn Olsson
Head of Technology
Centre for Business Solutions
Gothenburg School of Economics and Commercial Law
"SharpCoderMP" wrote:
hi,

i'm writing a console application and i would like to be able to safely
retrive password from the user, so noone can see how it is being typed.
consider this scenario:
Console.Write("Enter password:");
string pass = Console.ReadLine()

when this is called and user types, his passsword is displayed on the
screen. i would like to avoid that, and do not print any characters or
eventually print only '*' char for each user typed char. i thought i
could use Console.Read() in a loop, but i can't make it work the way i
want. it seems that Console.Read() works almost the same as
Console.ReadLine() - it waits until user types what he needs and hits
[enter] and then starts reading char by char.

i know i'm missing something...

Nov 17 '05 #2

P: n/a
thanks! that's exacly what i need. i was browsing codeproject but didn't
came acros this. thanks for the link... boy it looks preety twisted :P

Björn Olsson wrote:
Check this article out. It will help you, dont know if this is the "correct"
way to do it but it does the trick.

http://www.codeproject.com/dotnet/Co...swordInput.asp

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.