From reedwv@Stupi.SE Thu Aug 17 15:39:30 1995 Date: Thu, 17 Aug 1995 14:39:38 +0100 (BST) From: Bill Reed X-Sender: reedwv@expu79 To: Ulla Sandberg Subject: Re: SUMMARY: Password generator In-Reply-To: Message-Id: Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Dunno if ypu've got this one ? randpass B.P. Exploration email: reedwv@expu79.stp.xfi.bp.com Uxbridge One reedwv@txpcap.hou.xwh.bp.com Harefield Road tel: +44 1895 877429 Uxbridge UB8 1PD U.K. fax: +44 1895 877345 * User Error! Replace User and strike any key... --------------------------------------------------------- #include #include extern char *crypt(); #ifdef RAND48 #define random lrand48 #define srandom srand48 #endif #define DEFAULTLENGTH 8 /* default length of passwords */ char vowels[] = "aeiou"; char consonants[] = "bcdfghjklmnpqrstvwxyz"; char saltchars[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; #define Vowel() vowels[random() % (sizeof(vowels)-1)] #define Consonant() consonants[random() % (sizeof(consonants)-1)] #define Saltchar() saltchars[random() % (sizeof(saltchars)-1)] main(argc, argv) int argc; char *argv[]; { int howmany, count, chr, length = 0, pid; char pwsalt[3], password[20]; if (argc < 2) { fprintf (stderr, "usage: %s howmany [length]\n", argv[0]); exit (1); } howmany = atoi (argv[1]); if (argc > 2) length = atoi (argv[2]); if (length == 0) length = DEFAULTLENGTH; else if (length < 6) length = 6; else if (length > 16) length = 16; pid = getpid(); srandom(((int)(time((time_t *)0))/pid)+pid+3873); pwsalt[3] = 0; for (count = 0; count < howmany; count++) { pwsalt[0] = Saltchar(); pwsalt[1] = Saltchar(); password[0] = 0; for (chr = 0; chr < length; chr += 2) password[chr] = Consonant(); for (chr = 1; chr < length; chr += 2) password[chr] = Vowel(); for (chr = 0; chr < length; chr++) if (!(random() % 3)) password[chr] += 'A' - 'a'; printf ("%-20s%s\n", password, crypt(password, pwsalt)); } } ----------------------------------------------------------------------------------