PHP Логин системы Lua ОБНОВЛЕННЫЙ КОД

Я создаю приложение, которое требует от пользователя зарегистрироваться / войти, и я не смог хэшировать пароли, потому что я использовал бесплатную версию 000webhost, которая позволяет 5.2. Поэтому я переключил свой веб-хостинг и использовал код с моего сайта, чтобы я мог хэшировать пароли. Код регистрации работает и хэширует пароли, но код входа не работает, и я менял его несколько раз.

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

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …