Hide password in Command Line - Console Application in Windows 2000

Posted on 2004-04-29
Medium Priority
Last Modified: 2007-12-19

I am working on a commnad line Application in C# on Windows 2000. I want to let user enter the password on command prompt, How I can hide the typed characters (the password text), after asking to input?

Question by:jss99
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 10954157
Hi jss99,
    I think this link will bring you to the way to hide password on Commandline Applicaiton.
    Any problem, please let me know.

Author Comment

ID: 10954650
Thanks, but this "ConsoleKeyInfo" thing does not work for me. I am using Framework 1.1 and VS .net 2003. Is there any special reference needs to be added?

Expert Comment

ID: 10956386
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)
            if (cki.Key == ConsoleKey.BackSpace)
                  if (sb.Length > 0)

      Console.WriteLine("Your password is: {0}", sb.ToString());


Accepted Solution

Vaishali_chaudhry earned 375 total points
ID: 10956795
If i have understood the Q well...you are asking the user to enter the passwprd on the command prompt and then when he types the passwprd...you want the passwd not to be visible .

See the following sample:it uses ConsoleEx.dll

using System;
using Microsoft.GotDotNet;

namespace ConsoleApplication1
      /// <summary>
      /// Summary description for Class1.
      /// </summary>
      class Class1
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            static void Main(string[] args)
                  char c='a';
                  string s="";
                  Console.WriteLine("Enter your password:");
                  Console.WriteLine("Your password is :{0}",s);


you can download ConsoleEx.dll from http://www.gotdotnet.com/community/usersamples/Default.aspx?query=ConsoleEx

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month10 days, 19 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question