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