#!/usr/local/bin/perl -w #----------------------------------------------- # Login v6 # # Purpose: Receive username and password through # CGI, and verifies them with a list of usernames # and passwords. Prints whether the user is # verified. # The same as login5.cgi, but print a search form # instead of just saying the user is verified. # # Author: H.L. Hiew # Created: 10/07/2000 # Last modified: 12/08/2001 # #----------------------------------------------- use CGI qw(:standard) ; # get the user-supplied name and passwd from CGI my $username = param("name") ; my $passwd = param("passwd") ; # open the password file for reading. If fail, stop the script with # an error message. open(PWFILE, ") # read the lines in the file one at a time { chomp $line ; # remove the newline character at the end of the line ($usr, $pw) = split(/;/,$line) ; if (($usr eq $username) && ($pw eq $passwd)) { $verified = 1 ; } } close(PWFILE) ; if ($verified){ &PrintSearchForm($username) ; } else { &PrintAccessDenied($username) ; } # # -------------------------------------------------- # SUBROUTINES # -------------------------------------------------- # # # A subroutine to print the HTML document which says # that the user is not verified. # Parameters: 1. a username string # sub PrintAccessDenied { my ($user) = @_ ; print <

Access Denied


$user is not verified.

END } # end of sub PrintAccessDenied # # A subroutine to print the HTML form to allow a user to # search for quotes. # Parameters: 1. a username string # sub PrintSearchForm { my ($user) = @_ ; print < Search Form

Search Engine for Quotations


Welcome, $user. Please type in a name, then click the submit button.

Quoter's name:

Note: in this example, try searching for "Kennedy", or "Homer", or "John". See the sample quotes.txt for the full list.

END } # end of sub PrintSearchForm # # Note that having action="search.cgi" above means that the search.cgi # script must be in the same directory as this script. # # I won't break down search.cgi step-by-step as I did with login.cgi. You # should be able to understand it now that you have gone through how the # login.cgi script was constructed. Make sure you go through the textbook # and do the lab exercises. You will need to know more about perl than what # appears in these sample scripts to complete al requirements in Assignment # 2. You may use these examples as the basis for the assignment though. # #