Hello,
I am a new member.In my college we are to make a program to store usernames and passwords in a file, and when a user enters a correct username and password, "authentication" must be granted to him.But,in my code, even though on entering the correct username and password, there is no authentication.
Here is the code :
If any member is able to help me, please do.Code:#include<stdio.h> #include<conio.h> #include<string.h> struct records { char usr[10]; char pass[15]; }list; void main() { char filename[10]; int res,flag=0; char username[10],password[15]; FILE *fp; long n,q; struct records *p; p=&list; clrscr(); fp=fopen("Rec","a+"); strcpy(list.usr,"nitin"); strcpy(list.pass,"kasbekar"); fprintf(fp,"%s %s",p->usr,p->pass); strcpy(list.usr,"rahul"); strcpy(list.pass,"dixit"); fprintf(fp,"%s %s",p->usr,p->pass); strcpy(list.usr,"abhishek"); strcpy(list.pass,"dwivedi"); fprintf(fp,"%s %s",p->usr,p->pass); n=ftell(fp); fclose(fp); fp=fopen("Rec","r"); printf("Enter username "); scanf("%s",username); printf("Enter password "); scanf("%s",password); printf("\n%d\n",n); while(ftell(fp)<n) { fscanf(fp,"%s %s",list.usr,list.pass); //q=ftell(fp); if(strcmp(list.usr,username)==1&&strcmp(list.pass,password)==1) { printf("\n %d ",ftell(fp)); flag=1; break; } else { continue; }} if(flag==0) printf("Incorrect username/password "); else printf("User authenticated "); fclose(fp); getch(); }
Thank you.



LinkBack URL
About LinkBacks


