Guest User

Untitled

a guest
Dec 11th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <sys/types.h>
  5. #include <sys/wait.h>
  6. #include <unistd.h>
  7. #include <sys/time.h>
  8. #include <pwd.h>
  9. #include <shadow.h>
  10. extern char *l64a ();
  11. extern char *pw_encrypt();
  12.  
  13. char *crypt_make_salt (void)
  14. {
  15. struct timeval tv;
  16. static char result[40];
  17.  
  18. result[0] = '\0';
  19. strcpy (result, "$1$"); /* magic for the new MD5 crypt() */
  20.  
  21. // Generate 8 chars of salt, the old crypt() will use only first 2.
  22.  
  23. gettimeofday (&tv, (struct timezone *) 0);
  24. strcat (result, l64a (tv.tv_usec));
  25. strcat (result, l64a (tv.tv_sec + getpid () + clock ()));
  26.  
  27. if (strlen (result) > 3 + 8) /* magic+salt */
  28. result[11] = '\0';
  29.  
  30. return result;
  31. }
  32.  
  33. int main()
  34.  
  35. {
  36. char *salt;
  37. char *cp;
  38. char *CryptP;
  39. char *NCryptP;
  40. struct spwd *spwd;
  41. struct spwd *getspnam();
  42.  
  43.  
  44.  
  45. // create new MD5 crypt password
  46. salt=crypt_make_salt();
  47. NCryptP = crypt("myPassword",salt);
  48. printf("\nNew password = %s \n",NCryptP);
  49. printf("salt = %s \n\n",salt);
  50.  
  51.  
  52. return 0;
  53. }
Add Comment
Please, Sign In to add comment