#!/usr/bin/perl
use strict;
use warnings;
#Written by Tyler Cruz, any modifications or use of this script please
#email me first at tylercruz@hotmail.com
#http://www.101h.com/tyler/perl/ for more of my code
my $username;
my $password;
my @array;
my @splitarray;
my $flag = "fail"; #flag to test if username/password matches
print "Content-type: text/html\r\n\r\n";
print "Please log in";
print "Username> "; ## Get user input, remove trailing \n
$username = <stdin>;
chomp $username;
print "Password> "; ## Get user password, remove trailing \n
$password = <stdin>;
chomp $password;
open (FH, "pw.txt"); #opens password file and stores it in @array
@array = <FH>;
close FH;
for (@array) {
@splitarray = split (/:/, $_); #basically differenciates the username and password on each line in the array
if ($splitarray[0] eq "$username" && $splitarray[1] eq "$password") {
$flag = "pass"; #test for match
}
else {
     
$flag = "fail"; #test for fail
}
}
if ($flag eq "fail") {
print "\nSorry, login failed.";
}
elsif ($flag eq "pass") {
print "\nLogin successful!";
}
