#!/usr/bin/perl # Michael Tartaglia # Password program creates accounts and verifies entries, # passwords are stored in "password.txt" use CGI ':standard'; require template; my $fileName = "password.txt"; template::startHTML("Program # 5","Secure Page 2"); if ($ENV{'QUERY_STRING'} ne "") { # IF THERE WAS A QUERY... my $mesg = ""; if (param('new') ne "1") { # IF A NEW ACCOUNT ISN'T REQUESTED my %PASSES; my $savedName; my $savedPass; my $pw = param('pw'); $pw = crypt("\L$pw\E", 3); my $name = param('name'); $name = "\L$name\E"; $name =~ s/://g; open (P, "<$fileName"); # OPEN PASSWORD FILE flock (P, 1); my @keys =

; close (P); foreach (@keys) { # SAVE PASSWORDS IN LOGIN-INDEXED HASH ($savedName, $savedPass) = split(/:/,$_); $PASSES{$savedName} = $savedPass; $PASSES{$savedName} =~ s/\n//; } if ($pw eq $PASSES{$name}) { # IF USER LOGIN AND PASSWORDS MATCH $mesg = "Great!" . " You would now have access!"; } else { # IF USER LOGIN AND PASSWORDS DIDN'T MATCH $mesg = "Incorrect!" . " Still no access."; } } elsif (param('new') eq "1") { # IF A NEW ACCOUNT IS TO BE CREATED my $x = saveID(); my $pw = param('pw'); $pw = "\L$pw\E"; my $name = param('name'); $name = "\L$name\E"; if ($x) { # IF THERE WAS NO TROUBLE MAKING ACCOUNT $mesg = "Account created!" . " Name: \"$name\", Password: \"$pw\""; } else { # IF, SAY, USERNAME ALREADY EXISTS $mesg = "Account not made." . " Username exists."; } } # PRINT MESSAGE print "\n\t", " $mesg 

"; } # PRINT HEADING, INFORMATION, AND INSTRUCTIONS print "\n\tThis page is an extention of ", "\n\tthe secure page.
(Try user \"houlihan\" with password ", "\n\t\"cs3300\".)
This program needs a little work.

", "\n\t", "\n\t", "\n\t
User name:
Password:
", "\n\t
", "\n\tnew user?", "\n\t
\n\n"; template::endHTML(); # SUBROUTINE READS IN PARAMETERS AND SAVES LOGIN AND ENCRYPTED PASSWORDS sub saveID { my $pw = param('pw'); $pw = crypt("\L$pw\E", 3); # PASSWORD ENCRYPTION 1-WAY my $name = param('name'); $name = "\L$name\E"; my $toSave = "$name:$pw\n"; my @stuff; my $x = 1; open (P, "<$fileName"); flock (P, 1); @stuff =

; close (P); foreach (@stuff) { ($a, $b) = split (/:/,$_); $x = 0 if ($a eq $name); } if ($x) { open (P, ">>$fileName"); flock (P, 2); print P $toSave; close (P); } return $x; }