Date: Sat, 11 Jan 1997 12:36:39 +0000 From: davidn@unique.usn.blaze.net.au (David Nugent) To: robert@nanguo.chalmers.com.au (Robert Chalmers) Cc: freebsd-questions@freebsd.org (bsd) Subject: Re: is there a crypt tool? Message-ID: <Mutt.19970111123639.davidn@labs.blaze.net.au> In-Reply-To: <199701112327.JAA22330@nanguo.chalmers.com.au>; from Robert Chalmers on Jan 12, 1997 09:27:29 %2B1000 References: <199701112327.JAA22330@nanguo.chalmers.com.au>
next in thread | previous in thread | raw e-mail | index | archive | help
Robert Chalmers writes: > More to the point, is there a crypt too anywhere. I can't find > anything on the CD. I know its in the libraries etc, but I need a program, > seen on Coherent believe it or not, called 'crypt'. Great for creating > passworded access on the fly. This is NOT the same thing, but I wrote it for the same purpose. Create a file containing user:password in plain text format. e.g. yourname:yourpassword anothername:anotherpassword Run "crypt filename >passwd_file", replacing filename with the name of the file that contains this data, and passwd_file with the name of the user/password file (typically .htaccess). #include <stdio.h> #include <unistd.h> #include <string.h> #include <time.h> const char ll[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz."; char * salt(void) { static char buf[32]; int i; for (i=0; i < 8; i++) buf[i] = ll[rand() % sizeof(ll)]; buf[i] = '\0'; return buf; } int main(int argc, char * argv[]) { int carg = 0; srand((unsigned)time(NULL) ^ getpid()); while (++carg < argc) { char * argp = argv[carg]; FILE * fp = fopen(argp, "r"); if (fp == NULL) perror(argp); else { char tmp[256]; while (fgets(tmp, sizeof tmp, fp) != NULL) { char * p = strchr(tmp, '\n'); if (p != NULL) *p = '\0'; p = strchr(tmp, '\r'); if (p != NULL) *p = '\0'; p = strchr(tmp, ':'); if (p == NULL) p = tmp; else ++p; strcpy(p, crypt(p, salt())); printf("%s\n", tmp); } fclose(fp); } } return 0; } Regards, David Nugent - Unique Computing Pty Ltd - Melbourne, Australia Voice +61-3-9791-9547 Data/BBS +61-3-9792-3507 3:632/348@fidonet davidn@freebsd.org davidn@blaze.net.au http://www.blaze.net.au/~davidn/
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Mutt.19970111123639.davidn>