Solved

Why isn't this working?

Posted on 2006-10-29
2
270 Views
Last Modified: 2008-03-06
I am racking my brain why this doesn't work.... for all I can tell it should. Why doesn't the password section work?

The if $username == $_POST['user'] evaluates true appropriately. The password part, however, does not evaluate properly.

            //Read the authentication file into an array
            $authfile = file('auth.txt');
            // Cycle through each line in file, searching for authntication match
            foreach ($authfile as $login)
            {
                  list($username, $password) = explode(":", $login);
                  // Remove the newline from the password
                  $password == trim($password);
                  
                  if ($username == $_POST['user'] )
                  {
                        if ($password == md5($_POST['pass']))
                        {
                              echo "AUTHROIZED.";
                              $authorized = true;
                              break;
                        }
                  }
            }            


Here is the content of auth.txt:

test:81dc9bdb52d04dc20036dbd8313ed055
test2:81b073de9370ea873f548e31b8adc081



0
Comment
Question by:DrDamnit
2 Comments
 
LVL 1

Accepted Solution

by:
cheetahshrk earned 500 total points
Comment Utility
You made an error when you trimmed the password gotten from the file.
$password == trim($password);
should be
$password = trim($password);
0
 
LVL 32

Author Comment

by:DrDamnit
Comment Utility
Nothing like sending 45 inutes looking for a mistake, and then having another set of eyes find it in 10 minutes! :-) Thanks!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now