CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Password Protecting a Sub

 



abockover
Deleted

Aug 2, 2000, 8:24 AM

Post #1 of 4 (913 views)
Password Protecting a Sub Can't Post

I have written a program that will view a flatfile database.

I would like to password protect it, but what I am trying will not work.

Below is the code I have.

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>



#!/usr/bin/perl

&parse_form;

$adminpass='hey';

print "Content-type: text/html\n\n";
print "<form action='view.cgi' method='post'>\n";
print "Password: <input type='password' name='password'>\n";
print "<br>\n";
print "<input type='submit' value='Login'>\n";
print "</form>";


if ($input{'password'} eq '$adminpass') {
&doView;
exit('0');
} else {
print "Invalid Password - Click the back button on your browser to try again.";
exit('0');
}

sub doView {

print "print the protected html";

}

sub parse_form {

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
if (length($buffer) < 5) {
$buffer = $ENV{QUERY_STRING};
}
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);

$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

$input{$name} = $value;
}
}
</pre><HR></BLOCKQUOTE>

Please tell me what is wrong!

Thanks,

Aaron


dws
Deleted

Aug 1, 2000, 10:47 PM

Post #2 of 4 (913 views)
Re: Password Protecting a Sub [In reply to] Can't Post

Think through the flow of the code, and add a couple of print "I'm here\n"; statements. Then ponder the results. This is basic debugging, and one way or another, you're going to have to learn it to advance as a programmer.

Also, for good form use exit(0) instead of exit('0')


[This message has been edited by dws (edited 08-02-2000).]


dws
Deleted

Aug 2, 2000, 8:29 AM

Post #3 of 4 (913 views)
Re: Password Protecting a Sub [In reply to] Can't Post

You need double quotes -- not single quotes -- around '$adminpass'


abockover
Deleted

Aug 2, 2000, 9:19 AM

Post #4 of 4 (913 views)
Re: Password Protecting a Sub [In reply to] Can't Post

Thanks,

I am a step in the right direction, but now it jumps right to the HTML that should be protected.

Thanks,

Aaron

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives