Jump to content

Checking POST against database result


Joshua4550

Recommended Posts

Hey,

 

I'm making a simple database-stored login system, but when i'm checking username/pass' of the $_POST and the database result, it seems to not work, but if I echo them both, theyre exactly the same...

 

$realpass = $array['adminpass'];
$realuser = $array['adminuser'];
if ($_POST['user'] == $realuser && md5(md5($_POST['pass']) . "rs-ps") == $realpass) {
      $_SESSION['adminuser'] = $realuser;
      $_SESSION['adminpass'] = $realpass;
      $_SESION['adminsite'] = $site;
      echo 'worked';
} else {
      echo 'failed';
}

 

This always says failed, although if i make it print $realuser, $realpass, and $_POST['user'] and $_POST['pass'], they match as they should!

 

What's wrong?!

 

Thanks alot guys!

Link to comment
Share on other sites

I took your original code and tried it. It worked fine. Somewhere your variables aren't getting the values you think they are getting. Put in print_r() functions and check everything.

 

I'm wondering where the array "$array" is initialized, since you have

<?php
$realpass = $array['adminpass'];
$realuser = $array['adminuser'];
?>

but you don't show where it's set.

 

Ken

Link to comment
Share on other sites

Yeah, sorry - I put the code into a function - the function seems to not be returning what it should though?

 

function correctPostUser() {
    if ( ($_POST['user'] == $realuser) && (md5(md5($_POST['pass']) . "rs-ps") == $realpass) ) {
      $_SESSION['adminuser'] = $realuser;
      $_SESSION['adminpass'] = $realpass;
      $_SESION['adminsite'] = $site;
      return true;
    }
    return false;
}

 

Any reason why when I do:

if (correctPostUser()) { echo 'true';} else { echo 'false';}

It always returns false.

 

I use it like this because I do that in Java, sorry if this is retarded, lol.

 

Thanks again.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.