Password System

Hi,

I have created a simple login system in C++, but I have a problem with it.
I am able to enter username and password but when I want to delete the password (using backspace) it doesn't delete but it prints *.

below is the code for masking the password..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  
	     int j=0;
	     char ch;
             char pass2[10]={""};
	     gotoxy(24,9);
	     cout<<pass2;

	     while((ch=getch())!='\r')
	     {

		putch('*');
		pass2[j]=ch;
		j++;

	     }


I need your help.
Last edited on
Check whether "ch" equals to 8 (code of backspace) and print "ch" itself instead of "*" in that case or move the cursor back if you can. something like

cout << "\b \b"; should be useful probably.
thanks for your reply.
Here is what I have done:

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
26
27
28
29
30
31
32
33

             int j=0;
	     char ch;
             char pass2[10]={""};
	     gotoxy(24,9);
	     cout<<pass2;


	     while((ch=getch())!='\r')
             {

		if(ch==8)
		{
			for(i=24;i<=24+j;i--);
			{
			gotoxy(i,9);
			cout<<"\b \b";
			}

		}
		else
		{
			putch('*');
			pass2[j]=ch;
			j++;
		}

	     }

	     gotoxy(24,19);
	     cout<<strlen(pass2);
	     getch();


with that I am now able to delete (backspace) the password. but the password I have is 6 character and when I delete for example 3 character of it, then retype it, it adds 3 characters to 6 and using strlen() it shows there is 9 character in pass2. but that 3 characters are not printed. It means that it doesn't delete the characters but it only hides it. And even if after deleting the 3 character I hit enter it accepts the password as correct.
Now, how to solve this issue?
Last edited on
Topic archived. No new replies allowed.