PHP和Swift:password_hash()上的致命错误

时间:2016-06-12 05:59:36

标签: php

我已经设置好我的注册并登录他们在服务器上的php文件,它可以与我的swift应用程序一起使用。我可以登录并轻松注册。但是当我添加password_hash()方法以保护用户密码时,我在尝试注册时会在Xcode上出错。有没有其他方法可以安全地存储密码,如果这不再有效。是的我安装了PHP 5.5.34:

通过Xcode

错误:

DATA: <br />
<b>Fatal error</b>:  Call to undefined function password_hash() in <b>/*/*/public_html/*/signup.php</b> on line <b>92</b><br />

signup.php

// Hash password and insert new user to table

$hashPassword = password_hash($password, PASSWORD_DEFAULT); 
$command = "    INSERT INTO USER
                (firstname, lastname, username, email, password)
            VALUES
                ('$firstname', '$lastname', '$username', '$email', '$hashPassword')";

if ( mysqli_query($DB, $command) ) {

    // Search for newUser

    $command = "SELECT * FROM USER WHERE username = '$username'";
    $sql = mysqli_query($DB, $command);

    if ( mysqli_num_rows($sql) != 0 ) {
        $newUser = mysqli_fetch_array($sql);

        $returnData["status"]       = "200";
        $returnData["message"]      = "Success!";
        $returnData["ID"]           = $newUser["ID"];
        $returnData["firstname"]    = $newUser["firstname"];
        $returnData["lastname"]         = $newUser["lastname"];
        $returnData["username"]         = $newUser["username"];
        $returnData["email"]        = $newUser["email"];

    }

    echo json_encode($returnData);
    return;

} else {

    $returnData["status"] = "400";
    $returnData["message"] = "Sorry, something must've went wrong. Please try again...";
    echo json_encode($returnData);
    return;

}

signin.php

// Find user from table and sign in

$command = "SELECT * FROM USER WHERE email = '$email'";
$sql = mysqli_fetch_array( mysqli_query($DB, $command) );

if ( isset($sql) ) {

    $hashPassword = $sql["password"];

    if ( password_verify($password, $hashPassword) ) {

        $returnData["status"] = "200";
        $returnData["message"] = "Success!";
        $returnData["ID"] = $sql["ID"];
        $returnData["username"] = $sql["username"];

    }

    echo json_encode($returnData);
    return;     

} else {

    $returnData["status"] = "400";
    $returnData["message"] = "Sorry, something must've went wrong. Please try again...";

    echo json_encode($returnData);
    return;

}

1 个答案:

答案 0 :(得分:0)

您可以使用此library获取password_*()个功能。还提供&lt; PHP 5.5支持。