Results 1 to 6 of 6

Thread: Perl\CGI small problem with script...

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2000
    Posts
    137

    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

  2. #2
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    maybe

    OPEN inx, $passfile;

    try that ?

  3. #3
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    open INX, "$passfile";
    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.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Oct 2000
    Posts
    137

    Unhappy Damn>...

    Well i tried all that but it still won't work. It alays goes to the BAD PASSWORD PAGE. I am so confused :-/

    Thanx,
    Mikelo2k

  5. #5
    scoutt
    Guest
    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.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Oct 2000
    Posts
    137

    Unhappy Thanx....

    thanx for your help, but i'm afraid it won't change much. Oh and the Lopp that checks it does never set auth to BAD, Auth is bad from the beginning, and if the Username\Pass matches one in the file, it automatically changes (permanently) auth to GOOD.

    Thanx,
    Mikelo2k

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width