• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 444
  • Last Modified:

Masking console output

Im writing a console app, which requires the user to provide a password, what I want to do is to mask the output, preferably with just "", stars (*) would work fine too.

Example output #1 (What I want to avoid):
Enter password: 123456

Example output #2 (Prefered solution):
Enter password:

Example output #3 (Accepted solution):
Enter password: ******
0
bjqrn
Asked:
bjqrn
  • 2
1 Solution
 
AlexFMCommented:
There is low-level support for this: read every character using Console::ReadKey(false) and optionally print * using Console.Write(Char) method. Stop when Enter is pressed.
Simple way: set Console::ForegroundColor equal to Console::BackgroundColor and call ReadLine.
0
 
DanRollinsCommented:
Sometime we forget that even in a Console app, it is possible to pop up a dialog box to get user input.   That's how I'd handle it.  

I'd also check for something like
    -u:UserName -p:Password
in the commandline parameters so the user could specify them for automatic (batch) operations.

-- Dan
0
 
DanRollinsCommented:
Two viable alternatives.  I recommend a split.
0
 
bjqrnAuthor Commented:
The first one was more what I looked for.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now