doutun9179 2016-07-27 00:26
浏览 33

无法登录在Android上运行

I recently worked with a PHP script that is supposed to hash the password on registration from the android app. The password will hash and be added to the database, but it won't let me login now. There are no error codes coming up either. Here is the code from Android:

public LoginRequest( String username, String password, Response.Listener<String> listener) {
    super(Request.Method.POST, REGISTER_REQUEST_URL, listener, null);
    params = new HashMap<>();
    params.put("password", password);
    params.put("username", username);

Here is the PHP script I am supposed to use:

    <?php
    require("./Password.php");

    $con = mysqli_connect("host", "user", "password", "database");

    $typeusername = $_POST["username"];
    $typepassword = $_POST["password"];

    $statement = mysqli_prepare($con, "SELECT * FROM user WHERE username = ?");
    mysqli_stmt_bind_param($statement, "s", $username);
    mysqli_stmt_execute($statement);
    mysqli_stmt_store_result($statement);
    mysqli_stmt_bind_result($statement, $userID, $name, $phone, $username, $password, $email);

    $response = array();
    $response["success"] = false;  

    while(mysqli_stmt_fetch($statement)){
        if (password_verify($typepassword, $password)) {
            $response["success"] = true;  
            $response["name"] = $name;
            $response["phone"] = $phone;
            $response["username"] = $username;
            $response["password"] = $password;
            $response["email"] = $email;
        }
    }

    echo json_encode($response);
?>

Update: This is based off of a template for a login PHP file with a few modifications for my needs. This is closer to what the original template looked like:

    <?php
    require("./Password.php");

    $con = mysqli_connect("host", "user", "password", "database");

    $username = $_POST["username"];
    $password = $_POST["password"];

    $statement = mysqli_prepare($con, "SELECT * FROM user WHERE username = ?");
    mysqli_stmt_bind_param($statement, "s", $username);
    mysqli_stmt_execute($statement);
    mysqli_stmt_store_result($statement);
    mysqli_stmt_bind_result($statement, $colUserID, $colName, $colPhone, $colUsername, $colPassword, $colEmail);

    $response = array();
    $response["success"] = false;  

    while(mysqli_stmt_fetch($statement)){
        if (password_verify($password, $colPassword)) {
            $response["success"] = true;  
            $response["name"] = $colName;
            $response["phone"] = $colPhone;
            $response["username"] = $colUsername;
            $response["password"] = $colPassword;
            $response["email"] = $colEmail;
        }
    }

    echo json_encode($response);
?>

This is supposed to work with a previous database that I had setup for a tutorial series that this template is based on, but it does not work either. With a regular login PHP code, I can login just fine, but I want to be able to use the hashed passwords in my database.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
    • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
    • ¥15 MATLAB中streamslice问题
    • ¥15 如何在炒股软件中,爬到我想看的日k线
    • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
    • ¥15 seatunnel 怎么配置Elasticsearch
    • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
    • ¥15 (标签-MATLAB|关键词-多址)
    • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
    • ¥500 52810做蓝牙接受端