#!/usr/bin/perl
use warnings;
#use strict; had to take this off to get the code to run
use CGI qw(:standard);
use CGI::Carp qw/fatalsToBrowser warningsToBrowser/;
use Digest::MD5 qw(md5 md5_hex md5_base64);
#assigning value to variables
$username = param("username");
$password = param("password");
$hashpass = md5_hex($password);
print header, start_html();
#creating an array from the flatfile that usernames and passwords are stored
#my @users = do { open my $fh, "<", "password.txt" or die $!; map { chomp; split /:/ } <$fh> };
# This is where I have been experimenting trying to get the hash to do what I have already done with a foreach loop
# Creating a hash to try and split up the incomming array into usernames and their associated passwords
#my %users = do { map { ($name, $value) = split (/:/, my $pair) } @users; };
#opening up the file in the preffered method does not allow the program to work correctly, I don't understand why
#open my $fh, "<", "password.txt" or die $!;
open (YYY, "password.txt");
@incomingarray=<YYY>;
foreach $pair(@incomingarray) {
($name,$value) = split (/:/, $pair);
$incomingarray{$name} = $value;
chomp $value;
}
close (YYY);
my $check=$incomingarray{$username};
chomp ($check);
if ($check eq $hashpass) {
print p("Hello"." ".$username);
}
else {
print p("Login failed.");
}
print end_html();