#!/usr/local/bin/perl -w #----------------------------------------------- # Login v5 # # 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 uses subroutines. # # Author: H.L. Hiew # Created: 10/07/2000 # Last modified: 10/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){ &PrintVerified($username) ; } else { &PrintNotVerified($username) ; } # # -------------------------------------------------- # SUBROUTINES # -------------------------------------------------- # # # A subroutine to print the HTML document which says # that the user is verified. # Parameters: None # sub PrintVerified { my ($user) = @_ ; print <

Login Page version 5


$user is verified.

END } # end of sub PrintVerified # # A subroutine to print the HTML document which says # that the user is not verified. # Parameters: 1. a username string # sub PrintNotVerified { my ($user) = @_ ; print <

Login Page version 5


$user is not verified.

END } # end of sub PrintNotVerified