#!/usr/bin/perl -T use strict 'vars', 'subs'; use CGI; use Digest::MD5; use Text::Template 'fill_in_file'; my $q = CGI->new; my $HOME = '/home/mjd/src/mac_mysql'; unless ($q->param('submit')) { # First referral -- display form my $html = fill_in_file("$HOME/authform.tmpl", HASH => { in => scalar($q->Vars), selfurl => $q->url, }, UNTAINT => 1, ); print $q->header(), $html; exit 0; } # Check password and issue credential my $credential = make_credential($q->param('username'), $q->param('password') ); my $cookie = $q->cookie(-name => $q->param('cookie'), -value => $credential, -path => '/', # Adjust this to suit yourself ); print $q->redirect(-uri => $q->param('return'), -cookie => $cookie, ); exit; sub make_credential { my ($user, $pass) = @_; my $ip = pack "C4", split(/\./, $ENV{REMOTE_ADDR}); my $creation_time = pack "N", time(); my $checksum = Digest::MD5->new->add($user, $ip, $creation_time, $pass); my $cred = join "", $ip, $creation_time, $checksum->hexdigest, $user; }