Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Password Protection problems

Status
Not open for further replies.

FurryGorilla

Technical User
Apr 11, 2001
76
GB
Unfortunately I do not have telnet access to my web server so have been trying to write a simple password script.

The script was taken from a tutorial I managed to find but it does not seem to work correctly. The script processes the form input but it does not seem to match up with the array. The password is never accepted unless you leave it blank, in which case it is validated.

The code is as follows:
#!/usr/bin/perl

require "cgi-lib.pl";

%passwords = ( "bob\n"=>"thebobinator\n",
"jeff\n"=>"jeffstheman\n",
"nick\n"=>"irock\n",);

&ReadParse(*input);

$uname = $input{'username'};
$pword = $input{'password'};

print "Content-type: text/html\n\n";
print &quot;<html><body>&quot;;

if ($pword eq $passwords{$uname}){
print &quot;Thank you for using our program $name&quot;;
}
else{
print &quot;You entered the wrong password, so get lost&quot;;
}

print &quot;</body></html>&quot;;

Any help would be greatly appreciated

Reagrds
Chris
 
Sorry, I don't have cgi_lib on this machine. If I had to guess, I would think that cgi_lib would remove the '\n's from the form inputs. You might try loosing the '\n's from you hash.

%passwords = (&quot;bob&quot;=>&quot;thebobinator&quot;,
&quot;jeff&quot;=>&quot;jeffstheman&quot;,
&quot;nick&quot;=>&quot;irock&quot;,);




Here is an exmple of doing it with CGI.pm.
I don't know it that is any help.

Code:
#!/usr/bin/perl
use CGI;
%passwords = (&quot;bob&quot;=>&quot;thebobinator&quot;,
        &quot;jeff&quot;=>&quot;jeffstheman&quot;,
        &quot;nick&quot;=>&quot;irock&quot;,); 

$cgi = new CGI;
$uname = $cgi->param('username');
$pword = $cgi->param('password');

print $cgi->header;
print $cgi->start_html;

if ($pword eq $passwords{$uname})
    {
    print &quot;Thank you for using our program $name&quot;;
    }
else{
    print &quot;You entered the wrong password, so get lost&quot;;
    }

print $cgi->end_html;

HTH


keep the rudder amid ship and beware the odd typo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top