Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**********************************************************************
- * programming_assignment_two.c
- * nurses software
- * 219322
- * version 1.0
- * *****************************************************************/
- #include <stdio.h>
- #include <string.h>
- #include <math.h>
- #include <stdlib.h>
- void screen();
- void login();
- void nursework();
- void crypt(unsigned char pass[9]);
- void verify(char name[9], unsigned char pass[9], char identity[5][6], char accesspw[5][9]);
- int main()
- {
- screen();
- return 0;
- }
- void screen(void)
- {
- char user[11], playerone[4][11];
- strcpy(playerone[0], "Nurse");
- strcpy(playerone[1], "nurse");
- strcpy(playerone[2], "Consultant");
- strcpy(playerone[3], "consultant");
- printf(" INITIALISING PROGRAM\n"
- " WELCOME TO: ACTION ON WEIGHT\n"
- " A Cheylesmore Software Focus Production\n"
- " Please Identify your self. Are you a nurse? or a Consultant?:"), scanf("%s", user);
- if (strcmp(playerone[0], user)==0 || strcmp(playerone[1], user)==0)
- {
- login();
- }
- else if (strcmp(playerone[2], user)==0 || strcmp(playerone[3], user)==0)
- {
- printf("\n\n This is the wrong program. Only accessible to NURSES.\n\n");
- return;
- }
- else
- {
- printf("\n\n Enter a valid input please or close the program.\n\n");
- main();
- }
- }
- void login(void)
- {
- char pass[9], name[9];
- printf("\n\n |||||||| LOGIN AS A NURSE ||||||||\n");
- printf(" username: "), scanf("%s", name);
- printf(" password: "), scanf("%s", pass);
- printf(" ||||||||||||||||||||||||||||||||||\n");
- FILE * inf;
- int next = 0;
- char identity[5][6], accesspw[5][9];
- inf = fopen("nurse_intel.txt", "r");
- while (!feof(inf))
- {
- fscanf(inf, "%[^:]:%s%*[^\n]%*c", identity[next], accesspw[next]);
- next++;
- }
- crypt(pass);
- verify(name, pass, identity, accesspw);
- }
- void verify(char name[], unsigned char pass[], char identity[][6], char accesspw[][9])
- {
- int next;
- for(next=0; next<6; next++)
- {
- if(strcmp(name, identity[next])==0 && strcmp(pass, accesspw[next])==0)
- {
- nursework();
- }
- else
- {
- printf("\n wrong username or password. Try again.\n");
- login();
- }
- }
- }
- void nursework(void)
- {
- printf(" //=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=//");
- }
- void crypt(unsigned char pass[])
- {
- char encryption;
- int i, key=8;
- for(i = 0; pass[i] != '\0'; ++i){
- encryption = pass[i];
- if(encryption >= 'a' && encryption <= 'z'){
- encryption = encryption + key;
- if(encryption > 'z'){
- encryption = encryption - 'z' + 'a' - 1;
- }
- pass[i] = encryption;
- }
- else if(encryption >= 'A' && encryption <= 'Z'){
- encryption = encryption + key;
- if(encryption > 'Z'){
- encryption = encryption - 'Z' + 'A' - 1;
- }
- pass[i] = encryption;
- }
- else if(encryption >= '0' && encryption <= '9'){
- encryption = encryption + key;
- if(encryption > '9'){
- encryption = encryption - '9' + '1' - 2;
- }
- pass[i] = encryption;
- }
- }
- printf(" STARTING verification.");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement