How can I do so that I can display star(*) instead of plain text for password in C++.
I am asking for password and it is plain pass on the screen.
How can I convert them in to star(*) so that user can not see the password while entering.
This is what I have currently
char pass[10]={"test"};
char pass1[10];
textmode(C40);
label:
gotoxy(10,10);
textcolor(3);
cprintf("Enter password :: ");
textcolor(15);
gets(pass1);
gotoxy(10,11);
delay(3000);
if(!(strcmp(pass,pass1)==0))
{
gotoxy(20,19);
textcolor(5);
cprintf("Invalid password");
getch();
clrscr();
goto label;
}
Thanks
You need to use an unbuffered input function, like
getch ()provided by curses library, or a console library of your OS. Calling this function will return the pressed key character, but will not echo. You can manually print*after you read each character withgetch (). Also you need to write code if backspace is pressed, and appropriately correct the inserted password.Here is a code which once i wrote with the curses. Compile with
gcc file.c -o pass_prog -lcurses