Nov 20, 2011 at 8:37am UTC
hi, i have done an user id n password program in c and i am storing the details in file..but when i try to login its not logging in......i am using turboc....plz help....this is the code.....
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
#include<dos.h>
#include<string.h>
struct new_user
{
char first_name[10],last_name[10];
char loginid[20],password[10],re_password[10] ;
};
void main()
{
char pasword[10],username[20];
int a,b;
FILE *fp;
int i=0,j=0,k=0;
struct new_user nu;
clrscr();
fp=fopen("pass.txt","wb");
if(fp)
{
printf("FIRST NAME = ");
scanf("%s",nu.first_name);
printf("LAST NAME =");
scanf("%s",nu.last_name);
printf("LOGIN ID = ");
scanf("%s",nu.loginid);
printf("PASSWORD = ");
do
{
if((nu.password[i]=getch())==13)
{
break;
}
else
{
printf("*");
}
i++;
}while(nu.password[i]!=13);
nu.password[i]='\0';
printf("\nRE-PASSWORD = ");
do
{
if((nu.re_password[j]=getch())==13)
{
break;
}
else
{
printf("*");
}
j++;
}while(nu.re_password[j]!=13);
nu.re_password[j]='\0';
if(strcmp(nu.password,nu.re_password)==0)
{
fwrite(&nu,sizeof(nu),1,fp);
printf("\n");
fclose(fp);
printf("\nwritten");
}
else
{
printf("\n%s",nu.re_password);
printf("\n%s",nu.password);
printf("\npassword mismatch cannot write the file");
}
}
else
{
printf("file cannot open");
}
getch();
clrscr();
/* fp=fopen("pass.txt","rb");
if(fp)
{
fread(&nu,sizeof(nu),1,fp);
printf("%s\n%s\n%s\n%s\n",nu.first_name,nu.last_name,nu.loginid,nu.password);
fclose(fp);
}
else
{
printf("\ncannot open");
}*/
// getch();
//clrscr();
printf("USER NAME = ");
scanf("%s",username);
printf("PASSWORD = ");
do
{
if((pasword[k]=getch())==13)
{
break;
}
else
{
printf("*");
}
k++;
}while(pasword[k]!=13);
pasword[k]='\0';
printf("\n%s",pasword);
fp=fopen("pass.txt","rb+");
rewind(fp);
while(fread(&nu,sizeof(nu),1,fp))
{
rewind(fp);
//a=strcmp(username,nu.loginid);
//b=strcmp(pasword,nu.password);
if(nu.loginid == username)//&&nu.password == pasword)
{
printf("logged on \n");
break;
}
// printf("%s\n%s\n%s\n%s\n",nu.first_name,nu.last_name,nu.loginid,nu.password);
}
if(feof(fp))
{
printf("\nit does not exist or invalid\n");
}
fclose(fp);
getch();
}
Nov 20, 2011 at 9:05am UTC
use choice switch case statement .
for the choice such as
"Enter 1 for login "
"Enter 2 for changing the user id and password . "
Nov 20, 2011 at 12:34pm UTC
i want to login with the same id which i have stored......its not logging in .......