views:

230

answers:

2

I am trying to cobble together a login script in PHP as a learning project.

This is the code for my database write when the user registers. Both of these values are written to the database.

 $this->salt = md5(uniqid());
 $this->password = md5($password.$salt);

Upon logging in, the following function is fired.

function challengeLogin($submittedPassword, $publicSalt, $storedPassword){
    if(md5($submittedPassword.$publicSalt) == $actualPassword){
        return 0;
    }else{
        return 1;
    };
}

Unfortunately, on stepping through my code, the two values have never equaled. Can someone help me understand why?

+1  A: 

Compare the raw values before it gets hashed with some basic echo statements. Either the salt is wrong, your password is wrong, or the hash somehow got screwed up.

TheLQ
+4  A: 

I think the problem in your code is that the $salt variable is undefined, so it is empty. You should use $this->salt

Change

$this->password = md5($password.$salt);

to

$this->password = md5($password.$this->salt);
Lombo
You're probably exactly right. This sort of stumble is exactly why I decided to take an object oriented approach. I'm comfortable with scripting, but functional and OO programming... not so much.
Chris Sobolewski