PDA

View Full Version : Adding username to simple password script


PudgiPod
03-20-2007, 09:53 PM
Hello,

I've been using a simple but effective (for my purposes) password script. The script only asks for a password, and I would like to also include a username. I don't know how to write a perl script, so I'm not sure how to make this happen. I did, however, figure out how to allow mulitple passwords. For example, password 'one' will take you to page 'one.html' and password 'two' will take you to page 'two.html'.

I would like for the user to type in their username and password, and if they match, they are sent to the appropriate page. I just don't know how to write this. So here is the script:

----------
$correctpass = "sample";
$correcturl = "http://www.mydomain.com/private/";
$anotherpass = "sample2";
$anotherurl = "http://www.mydomain.com/offlimits/";
$scriptlocation = "http://www.mydomain.com/cgi-bin/password.pl";
$loginurl = "http://www.mydomain.com/login.html";

# Read in form data
&parse_form;

$password = $input{'password'};
$function = $input{'function'};


if ($function eq "login") {
if ($password eq $correctpass) {
&goto_url;
}
if ($password eq $anotherpass) {
&another_url;
}
&badpassword;
}


sub badpassword {
print "Location: $loginurl\n\n";
}


sub goto_url {

print "Location: $correcturl\n\n";
}

sub another_url {

print "Location: $anotherurl\n\n";
}


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;
}
}
----------

If anyone has any ideas I would really appreciate it! Thank you.

PudgiPod

mlseim
03-23-2007, 02:38 PM
PudgiPod ...

just curious ...

When you enter the correct username and password, and are redirected
to the correct page, what happens then?

Is that other page protected? What keeps someone from just going to
the other page directly? Even if you have no links to it, that page URL
is accessible using browser history.

The direction I'm going is to send you off on a mission to learn about
Perl sessions and Perl log-in scripts that you will already find using Google.
By using sessions, you can control all of those "other pages".

But it's great you're trying to learn it by experimenting on your own.

Also ... do you have an HTML log-in page?
You'll need to have a username variable also ...
$username = $input{'username'};
$password = $input{'password'};
$function = $input{'function'};