Thanks to all that replied!:
jayl@latticesemi.com
andy@spl.co.il
sweh@mpn.com
RAVKRISH.IN.ORACLE.COM.ofcmail@in.oracle.com
wightman@sol.acs.uwosh.edu
rsk@itw.com
25741@labatt.com
jasonn@nabaus.com.au
Michael.Gordon@ee.ed.ac.uk
charles@Grafnetix.COM
MHILL@graver.com
raju@ecologic.net
hrussy@uniandes.edu.co
wiles@geordi.calspan.com
Original request:
Looking for a quick and dirty password encryption routine.
Ballots tallied, awards for the best routine are as follows:
Written in C by: Michael.Gordon@ee.ed.ac.uk
code follows....
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
main(argc,argv)
int argc;
char **argv;
{
char *extras="!@%*()-+={[}];<>?";
char *exclusions="0Ol1I";
char cleartext[9];
char *encrypted;
char *crypt();
char saltc[2];
int c,i,num;
long salt;
if (argc!=2) {
fprintf(stderr,"usage: pwdgen num\n");
exit(1);
}
num=atoi(argv[1]);
cleartext[8]='\0';
srand((int)time(NULL)+getpid());
while (num--) {
for (i=0;i<8;i++) {
do {
cleartext[i]=(rand() >> 24) & 0x7f;
} while (cleartext[i]=='\0' ||
!(isalnum(cleartext[i]) ||
strchr(extras,cleartext[i])) ||
strchr(exclusions,cleartext[i]));
}
salt=time(NULL)+rand();
/*
* This is taken from passwd.c - it somehow makes sure that
* the encrypted password consists of only a limited set of
* characters.
*
*/
saltc[0]=salt & 077;
saltc[1]=(salt>>6) & 077;
for (i=0;i<2;i++) {
c=saltc[i]+'.';
if (c>'9')
c+=7;
if (c>'Z')
c+=6;
saltc[i]=c;
}
encrypted=crypt(cleartext,saltc);
printf("%s\t%s\n",cleartext,encrypted);
}
return(0);
}
This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:11:43 CDT