Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  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. crypt(pass);
  72. verify(name, pass, identity, accesspw);
  73. }
  74. void verify(char name[], unsigned char pass[], char identity[][6], char accesspw[][9])
  75. {
  76. int next;
  77. for(next=0; next<6; next++)
  78. {
  79. if(strcmp(name, identity[next])==0 && strcmp(pass, accesspw[next])==0)
  80. {
  81. nursework();
  82. }
  83. else
  84. {
  85. printf("\n wrong username or password. Try again.\n");
  86. login();
  87. }
  88. }
  89. }
  90. void nursework(void)
  91. {
  92. printf(" //=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=//");
  93. }
  94. void crypt(unsigned char pass[])
  95. {
  96. char encryption;
  97. int i, key=8;
  98. for(i = 0; pass[i] != '\0'; ++i){
  99. encryption = pass[i];
  100. if(encryption >= 'a' && encryption <= 'z'){
  101. encryption = encryption + key;
  102. if(encryption > 'z'){
  103. encryption = encryption - 'z' + 'a' - 1;
  104. }
  105. pass[i] = encryption;
  106. }
  107. else if(encryption >= 'A' && encryption <= 'Z'){
  108. encryption = encryption + key;
  109. if(encryption > 'Z'){
  110. encryption = encryption - 'Z' + 'A' - 1;
  111. }
  112. pass[i] = encryption;
  113. }
  114. else if(encryption >= '0' && encryption <= '9'){
  115. encryption = encryption + key;
  116. if(encryption > '9'){
  117. encryption = encryption - '9' + '1' - 2;
  118. }
  119. pass[i] = encryption;
  120. }
  121. }
  122. printf(" STARTING verification.");
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement