Nusoap无法使用PHP password_hash功能?

时间:2016-02-06 02:55:10

标签: php web-services nusoap

我正在为.net的登录过程编写一个简单的Web服务。我在服务器端使用nusoap php库。在那个服务器端,我正在哈希给出密码并在数据库中查询它以检查是否有这样的哈希密码。但是在.net中我得到的错误是响应是text / html格式,同时它等待text / xml格式。错误是password_hash函数没有founden但这是php的内置函数。我在单独的.php文件中检查这些函数,并且它在加密和解密(password_verify)时没有错误。那么在这种情况下我哪里出错了? enter image description here enter image description here

这是我的代码;

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;
}

2 个答案:

答案 0 :(得分:0)

看起来你的标题出了问题。 服务器应该发回

header("Content-Type: text/xml\r\n");

而是发回

header("Content-Type: text/html\r\n");

也许检查一下你的WSDL文件或找出你没有将xml输出回客户端的原因

我想知道你是否遇到了这个错误https://github.com/fergusean/nusoap/blob/463c772ae805aed7f396d89e6dce1dc0ce4c038b/lib/class.soap_server.php#L295

答案 1 :(得分:0)

<强>更新# 我找到了解决方案在PHP-7中,即使PHP的手册页中说当我在nusoaps服务器端调用它时内置了password_hash,它也不会识别这个功能。当我把它称为单独的.php页面时,它可以工作。 所以最后我从github下载了密码哈希库,它运行得很好。 我想,我错误地安装了PHP-7,或者它是一个bug。