Guys please help me.... how to not include the backspace in the password field... coz whenever I'm trying to delete a character in the password field the backspace creates a character and include on the password field....
Here's a small program that lets you type a password and does not put the backspace key into the field. You should be able to incorporate this into your program.
( It's actually the program I helped you with earlier. )
You enter a password without checking like it was before, and then you ask for a user names, but put the response into the variable for the password. You should make two loops. The first gets the user, checking input like you did for password, but putting the response into the user variable, then do the same with password, AFTER verifying the user input.
#include <iostream>
#include <windows.h>
#include <conio.h>
using std::cin;
using std::cout;
using std::endl;
int main ()
{
char ch;
char mypass[5]="pass";
char user[6]="user";
int y=0;
char upass[5];
char uname[6];
cout<<"USER NAME : ";
do{
ch=_getch(); // Don't need more than 1 char for inputs
if(ch=='\x0D' || y==6) //enter is the 13 scan code
{
uname[y]='\0'; //null char, end of your uname string
break;
}
if(ch=='\x08' && y!=0) //scancode 8 is backspace
{
y--;
cout<<"\b \b";
}
else
{
uname[y]=ch; //assign the value 'ch' as your password
cout<<"*";
y++; // Increase AFTER assigning
}
} while(1);
if(strcmp(uname,user)==0)
{
cout<<"\n Welcome " << user << ". Now enter your password.." << endl;
y = 0; // Reset variable 'y' to 0, for start of password checking
}
else
{
cout<<"\n Denied. I don't know you.." << endl;
return 0;
}
cout<<"PASSWORD : ";
do{
ch=_getch();
if(ch == '\x0D' || y==5) //enter is the 13 scan code
{
upass[y]='\0'; //null char, end of your upass string
break;
}
if(ch == '\x08' && y!=0) //scancode 8 is backspace
{
y--;
cout<<"\b \b";
}
else
{
upass[y]=ch; //assign the value 'ch' as your password
cout<<"*";
y++; // Increase AFTER assigning
}
} while(1);
if(strcmp(mypass,upass)==0)
cout<<"\n Granted" << endl;
else
cout<<"\n Denied" << endl;
}