Hi All,

I am writing a code in C++ to implement Login screen which will accept user name and password from the user. Now my main concern is to hide that password to be sceen by the user.

suppose my password is "Rat420" so at the time of typing anything i want it to appear as "******".

That means i need "*" to be seen on screen for each and ever character, and the original password is not lost.

That depends. What I/O interface are you using?

Is it a console process? Are you using a GUI? What OS? What widget set?

There is no way to do this in standard C++. There are non-standard ways to get the job done, some of which are in common use, though. Knowing at least some of the information asked by Duoas will be necessary to try to help inform you of which non-standard methods may be available to you.

Yes it is a console process.
i am using Unix and using Sun C++ compiler
and also i am using GUI.

Agreed. If I remember correctly, the curses library actually has a function that does what you want...

That code will not work in unix. The idea to use a loop to get characters is fine, but you will still need to use curses to unbuffer your stdin.

(Besides wish, that code is old and non-standards compliant.)

There is a Buit in function called getpass in conio.h

Prototype : char *getpass(const char *prompt);

Displays the prompt string and then reads the password without echoing. Returns a pointer to a static string containing the input password.
Usage://include the conio.h and string.h

char a[20];

strcpy(a,getpass("Enter Pass"));
cout<<a;

>There is a Buit in function called getpass in conio.h
Maybe on your compiler's flavor of C++. Just because it works for you doesn't mean it works for everyone, so at the very least mention your compiler and OS.

That will not work in Linux.

The getpass() function is borrowed directly from <unistd.h>, and is outdated and unreliable.

Use curses.

[EDIT] Heh, too slow again...

This article has been dead for over six months. Start a new discussion instead.