On 2/11/2013 19:22, Wayne Morris wrote:
> Thank you very much for your reply. Let me see if I can answer you questions... Stand by to get confused...
You could do it in a CGI script on the server. Perl has a native 'crypt'
function and a Digest::MD5 module too (which I used to create my passwords).
Not sure about PHP, etc. I do almost all of my web server code in Perl
including using templates offline to build the pages.
Good luck.
Code snippets:
my $crypt_passwd;
if ($md5) {
my $ctx = Digest::MD5->new;
$ctx->add($passwd);
$crypt_passwd = $ctx->hexdigest;
} else {
$crypt_passwd = crypt_passwd ($passwd);
}
...
my @legal_enc = ('.', '/', '0'..'9', 'A'..'Z', 'a'..'z'); # legal encrypted chrs
...
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub crypt_passwd { # $crypted_passwd = crypt_passwd ($plainpasswd [, $salt]);
my $passwd = shift;
my $salt;
# if salt supplied
if (defined $_[0]) {
$salt = substr $_[0], 0, 2; # get first 2 chars for salt
# else create a salt using time, pid and rand
} else {
if ($chk_only) {
$salt = substr $enc_passwd, 0, 2; # get first 2 for salt
} else {
my $tmp = (time + $$) % 65536;
srand ($tmp);
$salt = $legal_enc[sprintf "%u", rand (@legal_enc)];
$salt .= $legal_enc[sprintf "%u", rand (@legal_enc)];
}
}
my $new_passwd = crypt ($passwd, $salt);
return $new_passwd;
}