Guysss help me please

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include<iostream>
#include<windows.h>
#include<string>
#include<iomanip>
#include <conio.h>
#include<stdlib.h>
using namespace std;
int main () 
{

	char username[5]="ryan"; 
	char password[7]="ubana"; 
	char uname[10];
	char pass[10];
	
	
	bool account=false;
	int cnt=0;
	while(1){ 
		system("cls"); 
		cout<<endl;
			cout<<endl;
				cout<<endl;
					cout<<endl;
						cout<<endl;
							cout<<endl;
								cout<<endl;
									cout<<endl;
										cout<<endl;
											cout<<endl;
												cout<<endl;
													cout<<endl;
														cout<<endl;
															cout<<endl;
															cout<<endl;
															cout<<endl;
															cout<<endl;
															cout<<endl;
															cout<<endl;
															cout<<endl;
															cout<<endl;
															cout<<endl;
															cout<<endl;
															cout<<endl;
															cout<<endl;
															cout<<endl;
															cout<<endl;
															cout<<endl;
															cout<<endl;
															cout<<endl;
															cout<<endl;
															cout<<endl;
															cout<<endl;
															system("color 3a");
		cout<<("\t\t\t\t\t\t\t\t\t\tUSERNAME: ");  
	        cin >> uname;          
       		cout<<endl;
       		cout<<endl;
       		cout<<endl;
                cout << "\t\t\t\t\t\t\t\t\t\tPASSWORD: ";
		
		int i=0;
		while(1)
		   { 
			pass[i]=getch(); 
			if(pass[i]==13)  
			{
				pass[i]='\0';
				break;
			}
			cout << "*";
			i++;	 		
		}	
		
		if(!strcmp(uname,username) && !strcmp(pass,password)) { 
			account=true;
			break;
		} 
		
		else     
		
		{
			cnt++;
			if(cnt==2) 
			   break;
			cout << "\nIncorrect username or password\n";
			cout << "No of try: "<<cnt <<endl;
			
			system("pause");

		}
	}
	if(account)	{
		cout << "\n\n\t\t\t\t\t\t\t\t\t\tAccess Granted";
		Sleep(2000);
		system("cls");
		Sleep(2000);
	
	} else 
	system("cls");
	{
	int x;
	int y;
	while (y>=1)
	{
		system("color 4c");
		 cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
		 for (x=3;x>=1;x--)
		 {
		 	cout<<"\n\n\n\n\t\t\t\t\t\t\t\t\t\tWARNING!! Intruder Alert!!\n\n\n";
		 	Beep(3000,2000);
		 }
		 system("cls");
	}
}
}
     
    



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....
you could add a case to handle backspaces similar to the case to handle returns.

if you develop this further as a windows app, you may find there are APIs to handle text input which will process backspace for you.
but i want a simple coding please
how to not include the backspace and use as a delete button
@vendetta2014

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. )

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
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include <windows.h>
#include <conio.h>

using std::cin;
using std::cout;
using std::endl;

int main ()
{
 char ch[5];
 char mypass[5]="pass";
 int y=0;
 char upass[5];
 cout<<"Enter PASSWORD: ";

 do{

	ch[y]=_getch();

	if(ch[y]=='\x0D' || y==4) //enter is the 13 scan code
	{
	 upass[y]='\0'; //null char, end of your upass string
	 break;
	}
	if(ch[y]=='\x08' && y!=0) //scancode 8 is backspace
	{
	 y--;
	 cout<<"\b \b";
	}
	else
	{
	 upass[y]=ch[y]; //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;
}
Last edited on
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <windows.h>
#include <conio.h>

using std::cin;
using std::cout;
using std::endl;

int main ()
{
 char ch[5];
 char mypass[5]="pass";
 char user[6]="user";
 int y=0;
 char uname[6];
 char upass[5];
 cout<<"Enter PASSWORD: ";
 cin>>mypass;
 cout<<endl;
 cout<<"Enter USERNAME:";
 cin>>user;
 do{

	ch[y]=_getch();

	if(ch[y]=='\x0D' || y==7) //enter is the 13 scan code
	{
	 upass[y]='\0'; //null char, end of your upass string
	 break;
	}
	if(ch[y]=='\x08' && y!=0) //scancode 8 is backspace
	{
	 y--;
	 cout<<"\b \b";
	}
	else
	{
	 upass[y]=ch[y]; //assign the value 'ch' as your password
	 cout<<"*";
	 y++; // Increase AFTER assigning
	}
 }	while(1);

 if(strcmp(mypass,"pass")==0 && strcmp(user, uname)==0)
	cout<<"\n Granted" << endl;
 else
	cout<<"\n Denied" << endl;
}



What's wrong with my code please correct me i just added a username field but there's a runtime error
@vendetta2014

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.
so I need to loop the do function?
@vendetta2014

You need 2 do loops.

I'll help you out. Here..

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#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;
}


EDIT: Changed a couple of misspellings I had.
Last edited on
Thank you very much for this
Topic archived. No new replies allowed.