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
https://forums.phpfreaks.com/topic/201202-checking-post-against-database-result/
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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.