In my functions file I have this code:
function password($password, $dbpassword = false){
if($dbpassword){
$password = mysqli_real_escape_string($GLOBALS["mysqli"], $_POST["$dbpassword"]);
if(empty($password))
$password = mysqli_real_escape_string($GLOBALS["mysqli"], $_GET["$dbpassword"]);
if(empty($password))
return false;
}
$hasher = new PasswordHash(8, false);
if (strlen($password) > 72)
return false;
else{
if($dbpassword){
$check = $hasher->CheckPassword($password, $dbpassword);
if ($check)
return true;
else
return false;
}else{
$hash = $hasher->HashPassword($password);
if (strlen($hash) >= 20)
return $hash;
else
return false;
}
}
}
and in another file (with includes to functions and to the PHPASS php file) I have this code:
$pass = password("Vlad");
if(password("Vlad", $pass)){
echo 11;
}else{
echo 22;
}
It returns 22. Why is that?
When you call your
passwordfunction with a second variable that is notNULL, it will returnfalseunless aPOSTorGETvariable is set when you call your page.The name of that
POSTorGETvariable needs to be the password hash of the password you hashed the first time you used your function as you are using:or
I doubt that the name of the form-field in your form is changing constantly so that would explain why the function always returns
falsethe second time you call it.