Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- #include <unistd.h>
- #include <sys/time.h>
- #include <pwd.h>
- #include <shadow.h>
- extern char *l64a ();
- extern char *pw_encrypt();
- char *crypt_make_salt (void)
- {
- struct timeval tv;
- static char result[40];
- result[0] = '\0';
- strcpy (result, "$1$"); /* magic for the new MD5 crypt() */
- // Generate 8 chars of salt, the old crypt() will use only first 2.
- gettimeofday (&tv, (struct timezone *) 0);
- strcat (result, l64a (tv.tv_usec));
- strcat (result, l64a (tv.tv_sec + getpid () + clock ()));
- if (strlen (result) > 3 + 8) /* magic+salt */
- result[11] = '\0';
- return result;
- }
- int main()
- {
- char *salt;
- char *cp;
- char *CryptP;
- char *NCryptP;
- struct spwd *spwd;
- struct spwd *getspnam();
- // create new MD5 crypt password
- salt=crypt_make_salt();
- NCryptP = crypt("myPassword",salt);
- printf("\nNew password = %s \n",NCryptP);
- printf("salt = %s \n\n",salt);
- return 0;
- }
Add Comment
Please, Sign In to add comment