Keith Morse wrote:
% On Mon, 24 Sep 2001, Kurt Wall wrote:
%
% > If you're interested, I can post the password encrypter.
%
% I'm interested in the topic as a whole. It appears as though I'll be
% managing more and more user email accounts. I've tried this before but
% ended cutting/pasting 50 plus `mkpasswd` to "passwd username". Don't want
% to have to do this every time. Searching on google, I've come across some
% hits, though I don't know their value.
Here's the promised code. I build it with:
$ gcc -Wall -ansi -pedantic crypt.c -o crypt -lcrypt
It takes two arguments, the password to encrypt, and a 2-character
salt value, then calls crypt(3) with these arguments, and spits out the
encrypted password. Thus:
$ ./crypt secretword xx
xxajz8eBhzJf6
It is a naive implementation, but it gets the job done. The salt value
should be randomly selected. If you use it in a production
environment, make sure to vary the salt value or the password or both.
If it breaks, you get to keep both pieces.
/*
* crypt.c
* Use the crypt(3) call to generate a DES encrypted password.
*/
#define _XOPEN_SOURCE
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <crypt.h>
int main(int argc, char *argv[])
{
char *buf;
if(argc != 3) {
fprintf(stderr, "USAGE: crypt {key} {salt}\n");
exit(EXIT_FAILURE);
} else {
if(strlen(argv[2]) != 2) {
fprintf(stderr, "Salt value must be 2 characters\n");
exit(EXIT_FAILURE);
}
buf = crypt(argv[1], argv[2]);
if(!buf) {
perror("crypt");
exit(EXIT_FAILURE);
}
}
puts(buf);
exit(EXIT_SUCCESS);
}
Have fun,
Kurt
--
"Necessity is the mother of invention" is a silly proverb. "Necessity
is the mother of futile dodges" is much nearer the truth.
-- Alfred North Whitehead
_______________________________________________
http://linux.nf -- [EMAIL PROTECTED]
Archives, Subscribe, Unsubscribe, Digest, Etc
->http://linux.nf/mailman/listinfo/linux-users