I want to mask my password with "*" while the user is inputting it in. I used the getch()
function but it accepts backspace and return as characters.
This is the code I have written:
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
char password[7];
char PASSWORD[7]="abc123";
pass:
cout<<"Enter the 6 character password: "<<endl;
for(int i=0;i<6;i++) {
password[i]=getch();
cout<<"*"; //To mask the user input with '*'
}
cout<<endl;
if(strcmp(password,PASSWORD)==0) {
cout<<"LOGIN SUCCESSFULL..."<<endl<<flush;
system ("PAUSE");
}
else{
cout<<"Incorrect Password;"<<endl;
goto pass; //goes back to "pass:" and asks for password input again.
}
return 0;
}
Please how can I make it accept numbers and alphabets only.