[ create a new paste ] login | about

Link: http://codepad.org/YYGmdknl    [ raw code | output | fork ]

Perl, pasted on Feb 13:
#!/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();


Output:
1
2
3
4
5
6
7
8
9
10
11
12
[Mon Feb 13 00:56:11 2012] t.pl: Use of uninitialized value in subroutine entry at t.pl line 11.
Content-Type: text/html; charset=ISO-8859-1

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
	PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"><head><title>Untitled Document</title>
[Mon Feb 13 00:56:11 2012] t.pl: readline() on closed filehandle YYY at t.pl line 27.
[Mon Feb 13 00:56:11 2012] t.pl: Use of uninitialized value in scalar chomp at t.pl line 36.
[Mon Feb 13 00:56:11 2012] t.pl: Use of uninitialized value in string eq at t.pl line 37.
</head><body><p>Login failed.</p></body></html>


Create a new paste based on this one


Comments: