A Stable Password Protection Program Like Facebook (Best Run in Turbo C++ 3.1)
Code:
/*:cool: Guys, This program make a file when its run. Run it and Understand it. and tell me, "can i improve in it more?*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char user[20],fltp[5]=".txt",flname[25],pswrd[35],cnfrm[35],login[35],pchek[35],c,ps,cn,lg;
int i,j,k,l;
FILE *usr;
clrscr();
gotoxy(25,23);
textcolor(12);
cprintf("Enter Your name:");//Note: this may be works as your username also. Name will be unique.
scanf("%s",&user);//Scanf ko graphical bna. entry control
strcpy(flname,user);
strcat(flname,fltp);
usr=fopen(flname,"r");
if(usr==NULL)
{
usr=fopen(flname,"w");
fprintf(usr,"Username: %s",user);
printf("Welcome!\nYou are a new user\nCreat your password below");
printf("\nEnter Password:");
retry:
j=0;
while((ps=getch())!=13)
{
printf("*");
pswrd[j]=ps;
j++;
}
pswrd[j]='\0';
printf("\nConfirm Password:");
k=0;
while((cn=getch())!=13)
{
printf("*");
cnfrm[k]=cn;
k++;
}
cnfrm[k]='\0';
if((strcmp(pswrd,cnfrm))==0)
{
fprintf(usr,"\nPassword: %s",cnfrm);
fclose(usr);
}
else
{
printf("Password didn't match! Try Again...\n");
printf("Enter password again:");
goto retry;
}
}
else
{ gotoxy(25,25);
cprintf("Password:");
l=0;
while((lg=getch())!=13)
{
printf("*");
login[l]=lg;
l++;
}
login[l]='\0';
i=0;
while((c=getc(usr))!= EOF)
{
if(c=='\n')
{
fseek(usr,10,1);
while((c=getc(usr))!= EOF)
{
pchek[i]=c;
i++;
}
}
}
pchek[i]='\0';
if((strcmp(login,pchek))==0)
{
gotoxy(25,27);
textcolor(11);
cprintf("Welcome Back %s",user);
}
else
{
gotoxy(19,27);
textcolor(11);
cprintf("Wrong Password! You are not authorised");
}
}
getch();
}