Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Console - hide the input from console window while typing

I'm using Console.ReadLineto read the input of the user. However, I want to hide/exclude the inputted text on the console screen while typing. For example, when the user writes "a", it writes "a" to the console and then I will have a variable with the value "a". However, I don't want "a" to be written on the console's output.

How can I do that?

like image 611
user3265040 Avatar asked May 02 '14 17:05

user3265040


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

Is C language easy?

Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.


1 Answers

Here is a short implementation. thx @ojblass for the idea

System.Console.Write("password: ");
string password = null;
while (true)
{
    var key = System.Console.ReadKey(true);
    if (key.Key == ConsoleKey.Enter)
        break;
    password += key.KeyChar;
}
like image 78
dataCore Avatar answered Sep 19 '22 18:09

dataCore