Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <conio.h>
- struct database
- {
- char user[20];
- char pass[20];
- char email[40];
- }record;
- int main()
- {
- int count, choice, entries, i, j, ls, check=0;
- char mask;
- char fileDump[10000][50];
- char username[20];
- char password[20];
- FILE *fptr = fopen("E:\login_practice.bin","ab+");
- char dump[256];
- Again:
- printf("Welcome to user authentication program v1.2n");
- printf("n1. Registern");
- printf("n2. Loginn");
- printf("n3. Exitn");
- printf("nEnter your choice: ");
- scanf("%d", &choice);
- switch(choice)
- {
- case 1:
- printf("nHow many user you want to register?n");
- printf("nUsers = ");
- scanf("%d", &entries);
- for(count=1; count<=entries; count++)
- {
- FILE *fp = fopen("E:\email.bin", "ab+");
- printf("nEnter your email: ");
- scanf("%s", &record.email);
- fprintf(fp, "%sn", record.email);
- fclose(fp);
- printf("nEnter a username: ");
- scanf("%s", &record.user);
- fprintf(fptr, "%sn", record.user);
- printf("nEnter a password: ");
- for(j=0; j<10; j++)
- {
- mask = getch();
- if(mask == 13)
- {
- break;
- }
- else
- {
- record.pass[j] = mask;
- mask = '*';
- printf("%c", mask);
- }
- }
- fprintf(fptr, "%sn", record.pass);
- printf("nRegistration Successful.n");
- }
- goto Again;
- break;
- case 2:
- i=0;
- while(fgets(dump, sizeof(dump),fptr))
- {
- strcpy(fileDump[i], dump);
- i++;
- }
- ls=i;
- printf("nLines Scanned = %dn", ls);
- printf("nEnter your username: ");
- scanf("%s", &username);
- printf("nEnter your password: ");
- for(j=0; j<10; j++)
- {
- mask = getch();
- if(mask == 13)
- {
- break;
- }
- else
- {
- password[j] = mask;
- mask = '*';
- printf("%c", mask);
- }
- }
- strcat(username, "n");
- strcat(password, "n");
- for(i=0; i<=ls; i+=2)
- {
- if(strcmp(fileDump[i], username)==0)
- {
- if(strcmp(fileDump[i+1], password)==0)
- {
- check++;
- }
- }
- }
- if(check == 1)
- {
- printf("nLogin Successful.n");
- }
- else
- {
- printf("nInvalid Details Entered!n");
- }
- goto Again;
- break;
- case 3:
- exit(0);
- break;
- default:
- printf("nBad Choice!n");
- goto Again;
- break;
- }
- fclose(fptr);
- }
Add Comment
Please, Sign In to add comment