#
# Collect data and keep the user informed.
#
for (split (/\n/, $html_post_attributes)) {

	s/\s+//g;
	($variable, $value) = split (/=/, $_, 2);
	$username = $value if ($variable eq "username");
	$password = $value if ($variable eq "password");
	$peer = $value if ($variable eq "peer");
}
$login_flag = 0;
open (PASSWD, "< config/passwd");
while (<PASSWD>) {
	if (/^$username:/) {
	    $login_flag = 1;
	    ($junk, $encr, $userid, $junk1) = split (/:/, $_, 4);
	    $salt = substr($encr, 0, 2);

	    # Check for MD5-style crypt
	    if ($salt eq '$1') { ($salt) = ($encr =~ /^\$1\$([^\$]+)\$/); }

	    if (crypt($password, $salt) eq $encr) {
		$authenticated{$peer} = $userid;
		$login_flag = 2;
	    }
	}
}
close(PASSWD);
if ($login_flag < 2) {
	print CLIENT <<EOF;
<HTML>
<HEAD>
<TITLE>Incorrect Login</TITLE>
</HEAD>
<BODY BGCOLOR="white">
<P>
<H2>Incorrect Login</H2>
An incorrect username or password was entered. Please try again.
<BLOCKQUOTE>
<FORM METHOD=POST ACTION="$HTML_SERVER/auth/saint_auth_action.pl">
<INPUT TYPE=hidden NAME=peer VALUE=$peer>
User: <INPUT TYPE=text SIZE=10 NAME=username VALUE=saint><BR>
Password: <INPUT TYPE=password SIZE=10 NAME=password><P>
<INPUT TYPE=submit VALUE="log in">
</FORM>
</BLOCKQUOTE>
</BODY>
</HTML>
EOF
} else {
	open(PAGE, "< $html_root/$start_page");
	while (<PAGE>) {
		print CLIENT;
	}
	close(PAGE);
}
