print "Content-type: text/html\n\n"; use CGI qw(:standard); use SDBM_File; use Fcntl; #prevent perl from creating undeclared variables use strict; #declare variables my ($button, $account, $password); #assign values to variables $button = param('Button'); $account = param('Account'); $password = param('Pass'); if(length($account) == 5){ if ($button == "Create Account") { add(); } elsif ($button == "Tell Me My Password") { retrieve(); } }else{ print "<HTML>\n"; print "<HEAD><TITLE>Books Online</TITLE></HEAD>\n"; print "<h1>Please return to the form.</h1>\n"; print "Enter a valid account number. \n"; print "\n"; } exit; #*****user-defined functions***** sub add { my %accountinfo; if(length($password) >= 6 && length($password) <= 10){ tie(%accountinfo, "SBDM_File", "c09case2", O_CREAT|O_RDWR, 0666) or die "Error opening c09case2. $!, stopped"; $password =~ tr/abcdefghij/1234567890/; $accountinfo{$account} = $password; untie(%accountinfo); #create Web page print "<HTML>\n"; print "<HEAD><TITLE>Books Online</TITLE></HEAD>\n"; print "<h1>Books Online</h1>\n"; print "Your information has been recorded.\n"; print "\n"; } else { print "<HTML>\n"; print "<HEAD><TITLE>Books Online</TITLE></HEAD>\n"; print "<h1>Please return to the form.</h1>\n"; print "Enter a valid password. \n"; print "\n"; } }# end add sub retrieve{ my %accountinfo; my $pass_info; tie(%accountinfo, "SBDM_File", "c09case2", O_CREAT|O_RDWR, 0666) or die "Error opening c09case2. $!, stopped"; $pass_info = $accountinfo{$account}; untie(%accountinfo); $pass_info =~ tr/1234567890/abcdefghij/; #create Web page print "<HTML>\n"; print "<HEAD><TITLE>Books Online</TITLE></HEAD>\n"; print "<h1>Your password is</h1>\n"; print "$pass_info \n"; print "\n"; }
$button
tr
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)