Solved

Why isn't this working?

Posted on 2006-10-29
2
274 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Accepted Solution

by:
cheetahshrk earned 500 total points
ID: 17831154
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
ID: 17831191
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

726 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