> I need to add a password encryption function to a program I am
> writing and I cannot seem to get the function crypt() to work
> correctly. I need to be able to create a random salt. Can someone
> please show me the correct code to use to produce a random
> salt and to correctly invoke the crypt function? (I am adding all
> of the proper includes and compiling with the -lcrypt option.)
> Thanks in advance!
> Aaron Faby
> System Administrator/Technical Support
> Yourlink, Inc.
Here's how I create salts:
static char salt;
saltbuf = l64a(saltid);
salt = '\0';
salt = (*saltbuf) ? *saltbuf : '.';
salt = (*saltbuf & *(saltbuf+1)) ? *(saltbuf+1) : '.';
/* seed the random number generator from uid,pid,ppid and current time) */
srand(((unsigned int) time()) % (
(unsigned int) (getuid() + getpid() + getppid())));
salt = getsalt(rand()%4096);
if you now call crypt:
char *cryptpass = crypt(char *uncrypted_password,char salt)
then cryptpass will point to a static data area with the 13 character
password, the first two chars of which are the salt.
Opinions expressed herein are my own and may not represent those of my employer.