Advertisement
Guest User

bof

a guest
Aug 6th, 2022
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5.  
  6. int check_authentication(char *password) {
  7.  
  8. int auth_flag = 0;
  9. char *password_buffer;
  10. char *dept;
  11.  
  12. password_buffer = (char *) malloc (16);
  13. dept = (char *) malloc(10);
  14.  
  15.  
  16. strcpy(password_buffer, password);
  17.  
  18. if(strcmp(password_buffer, "AsiaPacificInst") == 0){
  19. printf("Your Department:");
  20. gets(dept);
  21. printf("\nUser from Department:\n");
  22. printf(dept);
  23. if(strcmp(dept,"NSF")==0) {
  24. auth_flag = 1;
  25. }
  26. }
  27.  
  28. else if(strcmp(password_buffer, "AsiaPacificUni") == 0){
  29. printf("Your Department:");
  30. gets(dept);
  31. printf("\nUser from Department:\n");
  32. printf(dept);
  33. if(strcmp(dept,"TM")==0) {
  34. auth_flag = 1;
  35.  
  36. }
  37. }
  38. else {
  39. auth_flag = 0;
  40.  
  41. }
  42.  
  43. return auth_flag;
  44. }
  45.  
  46. int main() {
  47. char errmsg[512];
  48. char outbuf[512];
  49. char user[20];
  50. char password[20];
  51. printf("Username: ");
  52. gets(user);
  53.  
  54. if (strcmp(user,"Adm1n") == 0){
  55. printf("Authorised User\n");
  56. sprintf(errmsg, "Authorised User %400s",user);
  57. sprintf(outbuf,errmsg);
  58. printf("Password: ");
  59. gets(password);
  60.  
  61. if(check_authentication(password)) {
  62.  
  63. printf("\n-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");
  64. printf(" Access Granted.\n");
  65. printf("-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");
  66. } else {
  67. printf("\n-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");
  68. printf("\nAccess Denied.\n");
  69. printf("\n-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");
  70. }
  71. }
  72. else {
  73. printf("Unauthorised user!\n");
  74. exit(0);
  75. }
  76. }
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement