#!/usr/bin/perl ##################################################### # Password Protection # Version 1.1 # ##################################################### # FORM SETUP: # # - The form can use both a GET and POST method. # # - The input for the password must be named "pw". # # - The input for the submit button can not have a name. # # - There can be no other inputs inside the form. # # EXAMPLE: # #
# ##################################################### # SCRIPT SETUP: # # - This script must be uploaded in ASCII mode. # # - The password is case insensitive. # # - Your $page1 and $page2 pages must exist. # # EXAMPLE: # # $password = "the site rules"; # # $page1 = "members_only.html"; # # $page2 = "bad_password.html"; # ##################################################### $password = "your_password"; $page1 = "correct_password_page.html"; $page2 = "incorrect_password_page.html"; ##################################################### if ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); ($name, $value) = split(/=/, $buffer); } elsif ($ENV{'REQUEST_METHOD'} eq "GET") { ($name, $value) = split(/=/, $ENV{'QUERY_STRING'}); } else { print "Content-type:text/html\n\n"; print "The form method must be \"GET\" or \"POST\"."; exit; } $password =~ tr/[A-Z]/[a-z]/; # Delete these two lines if you want $value =~ tr/[A-Z]/[a-z]/; # this script to be case sensitive. $value =~ tr/+/ /; $value =~ s/%([a-f0-9][a-f0-9])/pack("C", hex($1))/eg; if ($value eq $password) { print "Location: $page1\n\n"; } else { print "Location: $page2\n\n"; } exit;