|
-
Oct 21st, 2001, 03:24 PM
#1
Thread Starter
Addicted Member
Perl\CGI small problem with script...
I have a small problem with my code, it's a Login\Password Protetion script:
PHP Code:
#!/usr/bin/perl
#Setup
$passfile = "userpass.txt";
#Get Data From form -> Buffer String
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
#put Buffer String into Query String
$query = $buffer;
#Split Username and Password
($username,$password) = split(/&/,$query);
#Split Field name and data for username > User string
($junk,$user) = split(/=/,$username);
#Split Field name and data for password > Pass String
($junk,$pass) = split(/=/,$password);
#Open password File
open INX, "$passfile";
#Read File into @Data Array
@data = <INX>;
#Close Pass File
close INX;
#For each Username@Password combination in file
foreach $dataz(@data) {
#Split the USername and Password > chkuser and chkPass strings
($chkUser,$chkPass) = split(/@/,$dataz);
#Compare Usernames and Passwords
if ($user eq $chkUser and $pass eq $chkPass) {
#If User@Pass matches, Authorization is GOOD
$auth = "GOOD";
}
}
#If Authorization is "GOOD" then
if ($auth eq "GOOD") {
#Open current GOOD HTML Page
open(INZ,"curpage.src");
#Read Page into @datax array
@datax = <INZ>;
#Close Current Page File
close(INZ);
#Show the page
print "Content-type:text/html\n\n";
print "@datax";
}
#If Authorization is Not GOOD
else {
#Tell the user they are bad
print "Content-type:text/html\n\n";
print "<center>*********Bad Boy!***********";
}
The problem is that I use a HTML page for as the login page and even if the User Pass is correct it goes to wrong. All the syntaxes are correct. But I am pretty sure that :
PHP Code:
#Open password File
open INX, "$passfile";
Is not reading it. Any help is appreciated!
Thanx,
Mikelo2k
 
-
Oct 22nd, 2001, 02:35 AM
#2
Conquistador
maybe
OPEN inx, $passfile;
try that ?
-
Oct 22nd, 2001, 07:13 AM
#3
Black Cat
Try
Code:
open INX, "$passfile" or die "Couldn't open $passfile: $!\n\n";
to look for an access error there. Remember to set the permissions on that file so whatever your script runs as has at least read.
Josh
Get these: Mozilla Opera OpenBSD
I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.
-
Oct 22nd, 2001, 10:19 AM
#4
Thread Starter
Addicted Member
-
Oct 22nd, 2001, 03:24 PM
#5
I might as well take a gues at it too. how about this.
open (INX, '$passfile');
then in your split statement do this. it might not make a difference.
($chkUser,$chkPass) = split(/@/,$dataz,2);
but all in all I don't understand this
PHP Code:
foreach $dataz(@data) {
#Split the USername and Password > chkuser and chkPass strings
($chkUser,$chkPass) = split(/@/,$dataz);
#Compare Usernames and Passwords
if ($user eq $chkUser and $pass eq $chkPass) {
#If User@Pass matches, Authorization is GOOD
$auth = "GOOD";
}
}
it looks like it is splitting them up then testing each one to see if it equals $user and $pass. if it does it makes $auth = "GOOD"
but it looks like this could detect the first split and make $auth = "good" and then do the next one. which would not do it. it does have any code to detect if $auth is good to break out of the loop.
-
Oct 22nd, 2001, 05:40 PM
#6
Thread Starter
Addicted Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|