我正在为.net的登录过程编写一个简单的web服务。我在服务器端使用nusoap php库。在服务器端,我正在对给定的密码进行哈希运算,并在数据库中查询它,以检查是否存在这样的哈希密码。但是在.net中,我得到了一个错误,即响应是text/html格式,而它在等待text/xml格式。错误是password_hash函数找不到,但这是php的内置函数。我在单独的.php文件中检查了这些函数,并且它在加密和解密(password_verify)时都能正常工作。那么,在这种情况下,我哪里出错了?
这是我的代码;
function systemLogin($mycomplexlogin)
{
$result=NULL;
$conn=openConnection();
// Check connection
if ($conn->connect_error)
{
//return("Connection failed: " . $conn->connect_error);
return $result;
}
$EnterpriseId=mysqli_real_escape_string($conn,$mycomplexlogin["EnterpriseId"]);
$UserName=mysqli_real_escape_string($conn,$mycomplexlogin["UserName"]);
$Password=$mycomplexlogin["Password"];
$cost=10;
$hash="";
$hash=password_hash($Password, PASSWORD_BCRYPT, ["cost" => $cost]);
/* create a prepared statement */
$stmt = $conn->stmt_init();
// prepare and bind
if($stmt = $conn->prepare("SELECT * FROM mydatabase.USERS WHERE BINARY username=?"))
{
$stmt->bind_param("s", $UserName);
// execute query
$stmt->execute();
/* bind result variables */
$stmt->bind_result($resultId,$resultLastName,$resultFirstName,$resultAddress,$resultPosition,$resultManager,$resultUserName,$resultPass);
/* fetch value */
if($stmt->fetch())
{
if(password_verify($Password,$hash))
{
//date("Y-m-d H:i:s");
$token=date("Y-m-d H:i:s");
$result= array(
'Id' => $resultId,
'LastName'=>$resultLastName,
'FirstName' => $resultFirstName,
'Address'=>$resultAddress,
'Position'=>$resultPosition,
'Manager'=>$resultManager,
'Password' => $resultPass,
'UserName' => $resultUserName,
'Token' => $token
);
}
}
// close statement
$stmt->close();
}
mysqli_close($conn);
return $result;
}