Possible Duplicate:
Enter Password in C
Ask user to enter Password without showing the input characters on console?
Possible Duplicate:
Enter Password in C
Ask user to enter Password without showing the input characters on console?
You need to set the console to "no echo" mode. This depends on your particular OS. Here is an example of doing it for linux: http://www.cplusplus.com/forum/beginner/1988/page4.html#msg14522
See the GNU libc documenation for getpass, which gives a handy example of how to implement this:
#include <termios.h>
#include <stdio.h>
ssize_t
my_getpass (char **lineptr, size_t *n, FILE *stream)
{
struct termios old, new;
int nread;
/* Turn echoing off and fail if we can't. */
if (tcgetattr (fileno (stream), &old) != 0)
return -1;
new = old;
new.c_lflag &= ~ECHO;
if (tcsetattr (fileno (stream), TCSAFLUSH, &new) != 0)
return -1;
/* Read the password. */
nread = getline (lineptr, n, stream);
/* Restore terminal. */
(void) tcsetattr (fileno (stream), TCSAFLUSH, &old);
return nread;
}