Solved

Why isn't this working?

Posted on 2006-10-29
2
272 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
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Title # Comments Views Activity
How would I do this...? 2 32
Decrypt string by php 7 46
Get a subdirectory name from a url 5 27
ajax to record click 3 16
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

790 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