Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***********************************************************************
- * ActionOnWeightWrite.c
- * Allows nurses to input a username and password
- * writes the clients details to a file
- * Encrypts
- * Harry Bentham
- * 28/11/17
- * ********************************************************************/
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- struct date
- {
- int day;
- int month;
- int year;
- };
- struct login
- {
- char username[256];
- char password[9];
- };
- struct details
- {
- char fullName[256];
- struct date DOB;
- float height;
- float waist;
- float weight;
- char comment[256];
- };
- int login(struct login nurse);
- void enterDetails(void);
- void emptyBuffer(void);
- int main(void)
- {
- struct login nurse;
- if(login(nurse) ==0)
- {
- printf("Invalid Username or Password\n");
- } else
- {
- printf("Valid Username and Password\n");
- }
- enterDetails();
- return 0;
- }
- int login(struct login nurse)
- {
- FILE *fptr;
- struct login readNurse[6];
- int i =0;
- int j=0;
- int k=0;
- int passOrUser = 0;
- char ch = '\0';
- printf("\nUsername: ");
- scanf("%[^\n]", nurse.username);
- emptyBuffer();
- printf("\nPassword: ");
- scanf("%[^\n]", nurse.password);
- if((fptr = fopen("loginDetails.txt", "r"))== NULL)
- {
- printf("\ncan't open file loginDetails.txt\n");
- exit(1);
- }
- puts("file read");
- do
- {
- ch = fgetc(fptr);
- if(ch == EOF)
- {
- printf("\n");
- goto TEST;
- }else if(ch == ':')
- {
- printf("%c", ch);
- passOrUser = 1;
- k=0;
- } else if(ch == '\n')
- {
- printf("%c", ch);
- passOrUser = 0;
- k=0;
- i++;
- } else if(passOrUser == 0)
- {
- printf("%c", ch);
- readNurse[i].username[k] = ch;
- k++;
- } else if(passOrUser == 1)
- {
- printf("%c", ch);
- readNurse[i].password[k] = ch;
- k++;
- } else
- {
- exit(1);
- }
- }while(1);
- TEST:
- printf("%s : %s\n", readNurse[0].username, readNurse[0].password);
- printf("%s : %s\n", readNurse[1].username, readNurse[1].password);
- printf("%s : %s\n", readNurse[2].username, readNurse[2].password);
- printf("%s : %s\n", readNurse[3].username, readNurse[3].password);
- printf("%s : %s\n", readNurse[4].username, readNurse[4].password);
- j=i;
- for(i=0;j+1>i;i++)
- {
- if(strcmp(nurse.username, readNurse[i].username)==0)
- {
- if(strcmp(nurse.password, readNurse[i].password)==0)
- {
- fclose(fptr);
- return i++;
- }
- }
- }
- fclose(fptr);
- return 0;
- }
- void enterDetails(void)
- {
- ;
- }
- void emptyBuffer(void)
- {
- while(getchar() != '\n');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement