use strict;
use warnings;
use CGI;
my $q = new CGI;
my $user = $q->param('user');
my $password = $q->param('password');
# authenticate
my ($title,$body);
if ( &auth_user($user,$password) eq "OK" ){
($title,$body) = &validUser();
} else {
($title,$body) = &invalidUser();
};
# print html page
print qq(Content-type: text/html\n
$title
$body
);
#
# == end of main program
#
#
# authenticate user/passwords
#
sub auth_user{
my ($user,$password) = @_;
open(PASS, "pass") or die "Couldn't find password file.\n";
while(){
chomp;
my ($u,$p) = split(/\t/, $_, 2);
if ( ($u eq $user) && ($p eq $password) ){
close PASS;
return "OK";
}
}
close PASS;
return "notOK";
}
# valid
sub validUser {
my $title = "Login successful !";
my $body = q(
Login succesful!
Click here to continue
);
return ($title,$body);
}
# invalid
sub invalidUser {
my $title = "Login unsuccessful !";
my $body = q(
Invalid username\password.
Please try again.
);
return ($title,$body);
}