SHARE
TWEET

4 JAN part 2

a guest Dec 5th, 2019 196 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. /**********************************************************************
  3.     * programming_assignment_two.c
  4.     * nurses software
  5.     * 219322
  6.     * version 1.0
  7.     * *****************************************************************/
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <math.h>
  11. #include <stdlib.h>
  12.  
  13. void screen();
  14. void login();
  15. void nursework();
  16. void crypt(unsigned char pass[9]);
  17. void verify(char name[9], unsigned char pass[9], char identity[5][6], char accesspw[5][9]);
  18.  
  19. int main()
  20. {
  21.   screen();
  22.  
  23. return 0;
  24. }
  25.  
  26. void screen(void)
  27. {
  28.   char user[11], playerone[4][11];
  29.   strcpy(playerone[0], "Nurse");
  30.   strcpy(playerone[1], "nurse");
  31.   strcpy(playerone[2], "Consultant");
  32.   strcpy(playerone[3], "consultant");
  33.   printf("                              INITIALISING  PROGRAM\n"
  34.   "                           WELCOME TO: ACTION ON WEIGHT\n"
  35.   "                    A Cheylesmore Software Focus Production\n"
  36.   "           Please Identify your self. Are you a nurse? or a Consultant?:"), scanf("%s", user);
  37.   if (strcmp(playerone[0], user)==0 || strcmp(playerone[1], user)==0)
  38.   {
  39.     login();
  40.   }
  41.   else if (strcmp(playerone[2], user)==0 || strcmp(playerone[3], user)==0)
  42.   {
  43.     printf("\n\n    This is the wrong program. Only accessible to NURSES.\n\n");
  44.     return;
  45.   }
  46.   else
  47.   {
  48.     printf("\n\n         Enter a valid input please or close the program.\n\n");
  49.     main();
  50.   }
  51. }
  52.  
  53. void login(void)
  54. {
  55.   char pass[9], name[9];
  56.   printf("\n\n           |||||||| LOGIN AS A NURSE ||||||||\n");
  57.   printf("                    username: "), scanf("%s", name);
  58.   printf("                    password: "), scanf("%s", pass);
  59.   printf("           ||||||||||||||||||||||||||||||||||\n");
  60.  
  61.   FILE * inf;
  62.   int next = 0;
  63.   char identity[5][6], accesspw[5][9];
  64.   inf = fopen("nurse_intel.txt", "r");
  65.  
  66.   while (!feof(inf))
  67.   {
  68.   fscanf(inf, "%[^:]:%s%*[^\n]%*c", identity[next], accesspw[next]);
  69.   next++;
  70.   }
  71.   fclose(inf);
  72.   crypt(pass);
  73.   verify(name, pass, identity, accesspw);
  74. }
  75. void verify(char name[], unsigned char pass[], char identity[][6], char accesspw[][9])
  76. {
  77.   int next;
  78.   for(next=0; next<6; next++)
  79.   {
  80.     if(strcmp(name, identity[next])==0 && strcmp(pass, accesspw[next])==0)
  81.     {
  82.       nursework();
  83.     }
  84.     else
  85.     {
  86.       printf("\n          wrong username or password. Try again.\n");
  87.       login();
  88.     }
  89.   }
  90. }
  91. void nursework(void)
  92. {
  93.   printf("    //=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=//");
  94. }
  95. void crypt(unsigned char pass[])
  96. {
  97.   char encryption;
  98.   int i, key=8;
  99.   for(i = 0; pass[i] != '\0'; ++i){
  100.     encryption = pass[i];
  101.     if(encryption >= 'a' && encryption <= 'z'){
  102.         encryption = encryption + key;
  103.         if(encryption > 'z'){
  104.             encryption = encryption - 'z' + 'a' - 1;
  105.         }
  106.         pass[i] = encryption;
  107.     }
  108.     else if(encryption >= 'A' && encryption <= 'Z'){
  109.         encryption = encryption + key;
  110.         if(encryption > 'Z'){
  111.             encryption = encryption - 'Z' + 'A' - 1;
  112.         }
  113.         pass[i] = encryption;
  114.     }
  115.     else if(encryption >= '0' && encryption <= '9'){
  116.         encryption = encryption + key;
  117.         if(encryption > '9'){
  118.             encryption = encryption - '9' + '1' - 2;
  119.         }
  120.         pass[i] = encryption;
  121.     }
  122.   }
  123.   printf("               STARTING verification.");
  124. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top