Click here to run this example.
<form method=POST action="password.pl"> Enter your Password: <INPUT NAME="password" TYPE="TEXT" SIZE="10" MAXLENGTH="20"> <INPUT TYPE="SUBMIT" VALUE="Submit"> <INPUT TYPE="RESET"> </form>
(1) #!/usr/local/bin/perl ######################################################################## # password.pl # 11/26/97 by Zhanshou Yu # Any technical comment please send to : # zyu@rics1.uh.edu ######################################################################## (2) #Get the system date $date=`/usr/bin/date`; chop($date); #chop the last enter character (3) #Associate password with each data, password '1111' associate with data 86,etc. %PASSWD=('1111','86', '2222','55', '3333','40', '4444','100'); (4) #get the input data from the form. Here I use POST method read(STDIN,$buffer,$ENV{'CONTENT_LENGTH'}); (5) ($name,$value)=split(/=/,$buffer); #split name=value to name value $value=~tr/+/ /; #substitute plus sign with space sign $value=~s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; #decode hexdecimal to character (6) # print html header print" Content-type:text/html\n\n"; $flag=0; (7) #Check the received password in our list or not, if in, retrieve the data. foreach $item(keys%PASSWD) { if($item eq $value) { print "<title>Password Protection Retrieve Result</title>"; print "<center><h1> Password Protection Retrieve Result</h1> <center>"; print "<hr>"; print "<h4>Your retrieved data: <font color=#228b22>$PASSWD{$item}</font>.</h4>"; $flag=1; last; } } (8) # Not a valid password, print the error message. if($flag==0) { print "<title>Retrieve Error</title>"; print "<center><h1> Retrieve Error</h1>"; print "<hr>"; print "<h4> You enter the wrong password,get back and try again!</h4></center>"; } exit;
%PASSWD=('1111', '86', '2222', '55', '3333', '40', '4444', '100');This is the place where you put your data and password. In this example, we have four data: 86, 55, 40, 100, the passwords associated with them are 1111, 2222, 3333, 4444 respectively. You can add any number of data and password to the list. If you want to add more information, for example, if you want to add your name and SSN, you can define the associate array like this:
%PASSWD=('1111', 'Name : Zhanshou Yu SSN : 319920036 Score : 86', '2222', 'Name : Jame SSN : 225355783 Score : 55', '3333', 'Name : Lisa SSN : 324567878 Score : 40', '4444', 'Name : Jeff SSN : 123456789 Score : 100');
foreach $item(keys%PASSWD) { if($item eq $value) { print "<title>Password Protection Retrieve Result</title>"; print "<center><h1> Password Protection Retrieve Result</h1> <center>"; print "<hr>"; print "<h4>Your retrieved data: <font color=#228b22>$PASSWD{$item}</font>.</h4>"; $flag=1; last; } }For each item in the %PASSWD list, check whether the password is equal to the password entered. If two matched, print out the data associate with the password and set the found flag $flag=1. Then exit the loop.
if($flag==0) { print "<title>Retrieve Error</title>"; print "<center><h1> Retrieve Error</h1>"; print "<hr>"; print "<h4> You enter the wrong password,get back and try again!</h4></center>"; }