/*--------------------------------------------------------*/ /* password.c 08-aug-1997/bets */ /*--------------------------------------------------------*/ #include #include #include #include #include #include #include "password.h" /*--------------------------------------------------------*/ /* to64 */ /* From local_passwd.c */ /* (c) Regents of Univ. of California blah blah */ /*--------------------------------------------------------*/ void to64( register char *s, register long v, register int n ) { static unsigned char itoa64[] = /* 0...63 => ascii - 64 */ "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; while ( --n >= 0 ) { *s++ = itoa64[v&0x3f]; v >>= 6; } } /* end of to64() */ /*--------------------------------------------------------*/ /* password_encode */ /* this routine encodes a password parameter. */ /* return value: */ /* the routine returns a pointer to the encoded password */ /* string. */ /* argument: */ /* pw (input) = the password to encode */ /*--------------------------------------------------------*/ char *password_encode( char *pw ) { char salt[3]; (void)srand( (unsigned int)time( (time_t *)NULL )); to64( &salt[0],rand(),2 ); salt[2] = '\0'; /* added 05-jun-1998/bets */ return( crypt( pw,salt )); } /* end of password_encode() */ /*--------------------------------------------------------*/ /* password_okay */ /* this routine checks that the password parameter is */ /* okay, i.e. after being encrypted, it matches the */ /* encrypted password parameter. */ /* return value: */ /* the routine returns true if the passwords match; false */ /* otherwise. */ /* arguments: */ /* pw (input) = the password to check */ /* epw (input) = the encrypted password to check "pw" */ /* against */ /*--------------------------------------------------------*/ int password_okay( char *pw,char *epw ) { char salt[3]; strncpy( salt,epw,2 ); /*salt[3] = '\0'; changed 05-jun-1998/bets */ salt[2] = '\0'; return( ! strcmp( crypt( pw,salt ),epw )); } /* end of password_okay() */