dtnpzghys01643322 2017-01-01 18:37
浏览 72

PHP登录系统Lua更新代码

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
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 永磁型步进电机PID算法
    • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
    • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
    • ¥15 如何处理复杂数据表格的除法运算
    • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
    • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
    • ¥200 uniapp长期运行卡死问题解决
    • ¥15 latex怎么处理论文引理引用参考文献
    • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
    • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?