I am writing a Visual C++ program that executes from the command line that requires the user to input a password. How do I get the password to show up as asterisks instead of plain text as the user is typing it in?
Printable View
I am writing a Visual C++ program that executes from the command line that requires the user to input a password. How do I get the password to show up as asterisks instead of plain text as the user is typing it in?
read the threads on the faq board. and/or search these boards for password or similar because we have done this loads of times.
Code:#include "stdio.h"
#include "conio.h"
#define TRUE 1
#define ENTER 0x0D // Enter Key
int main()
{
// Yeah, yeah, i know = { NULL } isn't good to use
char str[80] = { NULL };
int idx = 0;
printf("\n\n Type your life away\n ---");
printf("\n Input [hidden] : ");
while(TRUE)
{
char ch = getch();
if(ch == ENTER)
break;
else
putchar('*');
str[idx] = ch; idx++;
}
printf("\n You entered : %s\n\n", str);
return 0;
}