-
November 28th, 2003, 01:07 PM
#1
Senior Member
password code improvement
I am new to the programming stuff.
The following the program to input a password and check it with the predefined password, "rambo", this program is working ok. Please let me know about the improvements needed in the code.//To Input and check the password.
Your suggestions will be appreciated.
_________________________________________________________________________
#include<stdio.h>
#include<conio.h>
void main()
{
char a[15];
int i,flag=0,x,y,post=0;
char g[]="rambo"; //predefining the password
clrscr();
i=0;
x=2;
y=10;
gotoxy(x,y);
printf("\n Please Enter the password:");
x=29;
y=11;
do
{
if(i<0) //limiting the value of i to 0
{
i=0;
}
if(x<29)
{
x=29;
}
a[i]=getch(); //getch() as it do not show the characters being //entered
if((a[i]=='\b') && (post==0))
{
post=1;
x=x-1;
}
if(a[i]=='\b')
{
--i;
gotoxy(--x,11);
continue;
}
i++;
gotoxy(x++,y);
}while(a[i-1]!=13);
a[i]=NULL;
for(i=0;a[i]!='\0' && g[i]!='\0';i++)
{
if(a[i]!=g[i])
{
flag=1;
}
}
gotoxy(15,15);
if(flag==0)
printf("\n The password is correct");
else
{
clrscr();
textcolor(5);
gotoxy(60,50);
cprintf("\n ACESS DENIED");
}
getch();
}
_______________________________END_______________________________
thanx.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|