PHP Login System Lua UPDATED CODE

吃可爱长大的小学妹 提交于 2019-12-20 06:03:28

问题


I am creating an app that requires the user to sign up/sign in and I couldn't hash the passwords because I was using the free version of 000webhost which allows 5.2 . So I switched my webhost and used the code from my website so I can hash the passwords . The register code works and hashes the passwords but the login code doesn't work and I've changed it multiple times .

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

(I am getting the else statement in this function ):

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

来源:https://stackoverflow.com/questions/41417974/php-login-system-lua-updated-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!