سؤال

I am currently working on console application.

I got an issue for login functionality in a console application .

If the user enters the username and password, then clicks the enter button, it will check other logic.

Now I want to the change the password(string)ordinary mode to password mode for anyone don't see the user input password .

Here is my code

Console.Write("Please enter the Password: ");
string password = Console.ReadLine();

I want to change the string (password) text mode to password, whenever the user type the password in console window.

هل كانت مفيدة؟

المحلول

Basically it comes down to a loop with Console.ReadKey(true) until the user presses Enter. Passing true for the intercept parameter to ReadKey will keep the pressed key from being displayed.

Check out the following post: How do I suppress keypress being printed to console in .NET?.

It allows you to read one character without displaying it in console. You then need to implement your own logic for storing the characters until enter is pressed.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top