PHP登录系统Lua更新代码

时间:2017-01-01 18:37:21

标签: php lua corona

我正在创建一个需要用户注册/登录的应用程序,我无法对密码进行哈希处理,因为我使用的是允许5.2的免费版000webhost。所以我切换了我的webhost并使用了我网站上的代码,所以我可以散列密码。注册码工作和哈希密码,但登录代码不起作用,我已经多次更改它。

login.php:

GLOBAL $username;
GLOBAL $pw;
GLOBAL $pw2;

if(isset($_POST['Login'])) {

$sql = "SELECT pw FROM users WHERE username = ?";

$stmt = mysqli_prepare($conn, $sql);
if ( !$stmt ) {
echo mysqli_error($conn);
exit;
}

$stmt->bind_param('s', $_POST['pw']);
$stmt->execute();

if ( !$stmt ) {
echo mysqli_error($conn);
exit;
}
// we found a row with that username, 
// now we need to check the password is correct

// get the password from the row
$stmt->bind_result($hashed_pwd);
$stmt->fetch();

if ( password_verify($_POST['pw'], $hashed_pwd) ) {
// password verified
        echo"success";
} else {
echo 'Incorrect username or Password.';
 }

login.lua:

local function userLogin( event )
if ( "ended" == event.phase ) then
 if emptyFields() == true then  

    else

    local parameters = {}
    parameters.body = "Login=1&username=" .. username.text .. "&pw=" .. pw.text

    local URL = "http://site.x10.bz/site/login.php"
    network.request(URL, "POST", networkListener, parameters)

    local headers = {} 

    headers["Content-Type"] = "application/x-www-form-urlencoded" 
    headers["Accept-Language"] = "en-US"

    parameters.headers = headers

end
end
end

(我在这个函数中得到了else语句):

local function networkListener( event )

if ( event.isError ) then
    print( "Network error.")
else
    if event.response == "success" then
        -- put the code here to go to where the user needs to be
        -- after a successful registration
        composer.gotoScene("userarea")

    else
        -- put code here to notify the user of the problem, perhaps
        -- a native.alert() dialog that shows them the value of event.response
        -- and take them back to the registration screen to let them try again

      local alert = native.showAlert( "Error Logging In", "There was an error logging in.", { "Try again" }  )

end
end
end

0 个答案:

没有答案