|> G'day,
|>
|> I was wondering whether somebody could please help me clarify the call
|> crypt and what is returns. I checked the man page and it seemed to pass
|> a code and the word to encrypt and it returned a pointer to the encrypted
|> string. I want to build a program which checks a password entered
|> against the system passwd file. Is the following call correct:
|>
|> encrypted = crypt("HELLO");
|>
|> I don't know. Any suggestions would be greatly apprreicated.
|>
|> I would prefer all my mail to be directed to:
|>
|> Thanking you in advance,
|>
|> Dean Thompson
You're welcome...you can abstract out the call to cracklib from the code
below.
Patrick
~~~~~~~~~~~~~~~~~ cut here for code example ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include <stdio.h>
#include <sys/types.h>
#include <sys/time.h>
#include <pwd.h>
#define TRUE 1
#define FALSE 0
main(argc,argv)
int argc;
char **argv;
{
char salt[3];
char crypt_pw[15];
char uncrypt_pw[256];
char *crack_msg;
struct passwd *pw;
unsigned short fail = FALSE;
/* Generate a random salt value starting with the current time */
srandom((int)time(NULL));
salt[0] = (random()%26) + ((random()&0x1)?'a':'A');
salt[1] = (random()%26) + ((random()&0x1)?'a':'A');
salt[2] = '\0';
do {
/* Get the new passwd */
strcpy(uncrypt_pw,getpass("Please enter the new password: "));
if(strcmp(uncrypt_pw,getpass("Please reenter the new password: ")) != 0){
fprintf(stderr,"Password not the same.\n");
fail = TRUE;
} else {
if ((crack_msg =
(char *)FascistCheck(uncrypt_pw, "/usr/local/admin/lib/pw_dict")
) != NULL) {
/* Crackable passwd */
fprintf(stderr,"That password could be broken because,\n");
fprintf(stderr,"%s.\n",crack_msg);
fail = TRUE;
} else {
fail = FALSE;
}
}
} while (fail == TRUE);
printf("%s\n",crypt(uncrypt_pw,salt));
return(0);
Quote:}
--
_______________________________________________________________________
/ These opinions are mine, and not Amdahl's (except by coincidence;). \
| (\ |
| Patrick J. Horgan Amdahl Corporation \\ Have |
| Phone : (408)992-2779 P.O. Box 3470 M/S 316 \\/ Will |
| FAX : (408)773-0833 Sunnyvale, CA 94088-3470 _/\\ Travel |
\___________________________O16-2294________________________\)__________/