Password problem in my c++ program

hello any one please help me quickly. Because i never forget ur timely help.
Iam having a c++ program with password function. The password function is working properly and password is taken in ***** sign.
my coding for password is

do{
cout << "\t\tEnter Username : "; //asking to enter username
cin>>User;

cout << "\t\tEnter Password : "; //asking to enter password


while(ch != '\r') //Loop until 'Enter' is pressed
{
ch = getch();
if(ch == '0')
{
switch(getch())
{
default:
break;
};
}
else if(ch == '\b') //If the 'Backspace' key is pressed
{
if(password.size() != 0) //If the password string contains data, erase last character
{
cout << "\b \b";
password.erase(password.size() - 1, 1);
}
continue;
}
else if(ch <= '9' && ch >= '0' || ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z') //If user enters 1-9, a-z, or A-Z, add it to the password and display an asterisk
{
password += ch;
cout << "*";
}
else
continue;
}

while(User!=secname && password!=secid);


iam using this inside a do while loop to repeat the password require function.

When user login to the system and enter password for the first time system takes the password and username even if input is a wrong username or password. Then again he asked to enter user name and taken but not take the password... enter password is just printed but not taking.





Last edited on
1. Can you format your code with the format tags please.
2. I can't see where you initialise/reset password and ch.
I think you require this much only .

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
		cout << "\t\tEnter Username : "; //asking to enter username
		cin>>User;
		cout << "\t\tEnter Password : "; //asking to enter password
	do
	{
		ch = getch();
		if(sizeof(password) != 0)
		{
			if( ch == '\\b')
			{
				putch('\\b');
				password.erase(password.size() - 1, 1);
                                continue;


			}
			
		}
		else if(ch <= '9' && ch >= '0' || ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z') //If user enters 1-9, a-z, or A-Z, add it to the password and display an asterisk
		{
			password += ch;
			putch('*');
		}
		
	}while {ch == '\\r');
Last edited on
Topic archived. No new replies allowed.