Need ADVICE badly

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
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<fstream.h>
#include<ctype.h>
#include<dos.h>
#include<graphics.h>
void graphic()
{ int Driver,Mode;
  Driver=DETECT;
  initgraph(&Driver,&Mode,"C:\\TC\\BGI");
}
void main()
{
  char i,chr='y';
  char Username[20];
  char password[20];
  int a=0,gr=0;
  clrscr();
  while(chr=='y')
{
  cout<<"                      LOGIN DETAILS";
  cout<<"\n\nUsername: ";
  gets(Username);
  cout<<"Password: ";
  while((i=getch())!= 13)//ASCII code for ENTER
  {if(i>32&&i<127)//ASCII codes for alphabets, numbers & symbols
    {password[a] = i;
     cout<<"*";
     a++;
    }

   else if(i=='\b')//When backspace is encountered
    {cout<<"\b \b";
     a--;
    }password[a]='\0';
  }

   if((strcmp(password,"admin\0")==0 && strcmp(Username,"ADMIN")==0))

  {cout<<"\n\nACCESS GRANTED";
   gr=1;
   chr='n';
   delay(350);
  }
  else
  {cout<<"\nACCESS DENIED";
   cout<<"\n\nDo you want to try again [y/n]: ";
   cin>>chr;
   clrscr();
   password[a]='\0';
  }
}
 if(chr=='n'&& gr!=1)
 {
  cout<<"Thank You for using our Software";
  cout<<"\nPress ENTER to EXIT...";
  delay(600);
  cout<<"\nExiting";
  delay(600);
  cout<<"...";
  delay(600);
  cout<<" ...";
  delay(600);
  cout<<" ...";
  delay(955);
 }

 else if(chr!='y'&& chr!='n'&& gr!=1)
   {cout<<"\nInvalid Entry";
    cout<<"\nPress ENTER to EXIT...";
    delay(600);
    cout<<"\nExiting";
    delay(600);
    cout<<"...";
    delay(600);
    cout<<" ...";
    delay(600);
    cout<<" ...";
    delay(955);
   }

 else if(gr==1)
 {graphic();
  setbkcolor(2);
  settextstyle(10,0,3);
  for(int i=0;i<350;i++)
     {i+=2;
      setcolor(i%5);
      outtextxy(i-200,65,"WELCOME TO");
      outtextxy(i-150,110,"CHJ PROJECT");
      delay(50);
      clrscr();
     }

  for(i=0;i<250;i++)
     {i+=2;
      setcolor(i%5);
      outtextxy(150,65,"WELCOME TO");
      outtextxy(200,110,"CHJ PROJECT");
      delay(20);
      clrscr();
     }
  closegraph();
  clrscr();
  cout<<"\nThe END";
  getch();
 }
 }
Last edited on
I advise you to make some sound investments and review your pension arrangements every year.
The problem with this is.......if by any chance password goes wrong.......it will always go wrong in that while loop until the program is stopped and run again......
second problem....when the welcome note arrives it brings a trail, how to eradicate that.....
third problem is i need help with the DELETE key or any other key in password.......plz dont make it complicated........by reading my source code u will already come to know of my poor knowledge of C++ so plz help me......
I am eagerly awaiting ur reply........
Last edited on
while((i=getch())!= 13) This statement is little confusing .
instead use while loop like while((i=getch())!= 'Z')
dont worry about that the prob is if the password goes wrong then it is always wrong even if we put it correct.....in order to be make the password correct we have re run the program......copy it and run u'll see

try this code .. Although i haven't checked it
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 while(chr=='y'  || chr=='Y'  )
	{
	  memset( Username , 0 , sizeof(Username ) ); 
	  memset( Username , 0 , sizeof(password) ); 
		cout<<"                      LOGIN DETAILS";
		cout<<"\n\nUsername: ";
		gets(Username);
		cout<<"Password: ";
		a = 0; 
		while((i=getch())!= 13)//13 is ASCII code for enter....so the loop goes on as long as ENTER key is not pressed
			{
				if(i>32&&i<127)//ASCII codes for alphabets, numbers & symbols
				{
					password[a] = i;
					cout<<"*";
					a++;
				}
				else if(i=='\b')//When backspace is encountered
				{
					cout<<"\b \b";
					a--;
				}
		} 
		password[a]='\0';
i didn't study memset ......
i edited the code with new one which i worked on.......
plz help me with graphics too.....
plz dont ignore....i badly need this code......
When you print "ACCESS DENIED" you don't set a to zero
Last edited on
so where should i add that......can u show me that particular.....

I tried the suggestion u told me and edited the above source code........plz check if that is correct
No that is not right. The problem is that if you don't reset a before inputting a new password the new password will be added after the old one. So if you first enter "ABC" as the password and next time you enter "123", the password will contain the string "ABC123".
so how do i reset a plz help......give me the the code of only that loop plz
Just make sure a is zero when you start reading the password.
plz show me the code......i understood what u meant but dont know where to put it......
plz dont ignore this
1
2
3
4
5
6
7
8
else
  {cout<<"\nACCESS DENIED";
   cout<<"\n\nDo you want to try again [y/n]: ";
   cin>>chr;
   clrscr();
   password[a]='\0';
   a = 0;          // you need to insert it here
  }
Thanks a lot it worked perfectly.......I am truly in debt to u......
Topic archived. No new replies allowed.