Guest User

Untitled

a guest
Jun 7th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. @hacky02:~$ cat /Uebungen/Aufgabenblatt01/Aufgabe02/auth.c
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <unistd.h>
  6.  
  7. char *salt = "$6$aGzikL66hsj/hs$";
  8.  
  9. int auth(char *username, char *password)
  10. {
  11. int result = 0;
  12. char pw_user[20];
  13. char * pw_hash;
  14.  
  15. // Prepare pw
  16. strcpy(pw_user, password);
  17. strcat(pw_user, username);
  18.  
  19. // Get Hash
  20. printf("\n\nUser: %s\n", username);
  21. printf("Password: %s\n", password);
  22. pw_hash = crypt(pw_user, salt);
  23. printf("Password Hash: %s\n", pw_hash);
  24.  
  25.  
  26. if(strcmp(username, "00") == 0 &&
  27. strcmp(pw_hash, "$6$aGzikL66hsj/hs$1KUTqGk7PDos.KzfFdMEjakeURJ5GzB.HtgVnKXDAEQZju2td0RSp0l0hLtMKWMpUpyF.V/JwZg79Nv5mZmQx/") == 0)
  28. {
  29. result = 1;
  30. }
  31.  
  32. return result;
  33. }
  34.  
  35. void printUsage()
  36. {
  37. printf("Usage: auth <username> <password>\n");
  38. exit(-1);
  39. }
  40.  
  41. int main(int argc, char *argv[])
  42. {
  43. if(argc < 3)
  44. printUsage();
  45.  
  46. if(auth(argv[1], argv[2]) == 1)
  47. {
  48. printf("\n\n#####################################################\n");
  49. printf("# #\n");
  50. printf("# !ACCESS GRANTED! #\n");
  51. printf("# #\n");
  52. printf("#####################################################\n\n\n");
  53. printf("Welcome %s!\n", argv[1]);
  54.  
  55. }
  56. else
  57. {
  58. printf("\n\n#####################################################\n");
  59. printf("# #\n");
  60. printf("# !ACCESS DENIED! #\n");
  61. printf("# #\n");
  62. printf("#####################################################\n\n\n");
  63. }
  64.  
  65.  
  66. return 0;
  67. }
Add Comment
Please, Sign In to add comment