Ruzy Posted January 12, 2016 Share Posted January 12, 2016 (edited) Hello, I am currently working on my login script but i am getting stuck at a error that the account is false. Debug: WARNING: login_s.lua:15: Bad argument @ 'setAccountPassword' [Expected account at argument 1, got boolean] WARNING: login_s.lua:17: Bad argument @ 'isGuestAccount' [Expected account at argument 1, got boolean] WARNING: login_s.lua:20: Bad argument @ 'logIn' [Expected account at argument 2, got boolean] ERROR: login_s.lua:29: attempt to index global 'userIDs' (a nil value) Code: local userIDs = {}; function PlayerLogin(userName,Password,checksave) if not (userName == "") then userName = string.lower(userName) if not (password == "") then callRemote("http://*****/login.php", function(response,extra,data,player,userName,Password) triggerClientEvent(player,"showNotification",player, "Connecting..", "information") if response == true then local acc = getAccount(userName) if not acc then acc = addAccount(tostring(userName),tostring(Password)) end if not getAccount(userName,Password) then setAccountPassword(acc,Password) end if (not isGuestAccount(acc)) then logOut(player) end logIn (player, acc, Password) if checksave == true then triggerClientEvent(player,"saveLoginToXML",getRootElement(),userName,Password) else triggerClientEvent(player,"resetSaveXML",getRootElement(),userName,Password) end setElementData(player,"getForumID",data["member_id"]) setElementData(player,"getForumName",userName) userIDs[player] = data["member_id"]; triggerClientEvent(player,"loginHide",player) triggerClientEvent(player,"showNotification",player, "Successfully logged in!", "success") elseif extra == 1 then triggerClientEvent(player,"showNotification",player, "Wrong username!", "error") elseif extra == 2 then triggerClientEvent(player,"showNotification",player, "Wrong password!", "error") end end ,"verifyPasswords", userName, Password, source) else triggerClientEvent(source,"showNotification",source, "Please enter your password!", "error") end else triggerClientEvent(source,"showNotification",source, "Please enter your username!", "error") end end addEvent("playerWantToLogin",true) addEventHandler("playerWantToLogin",getRootElement(),PlayerLogin) Can someone help me with this? Regards, Ruzy Edited January 24, 2016 by Guest Link to comment
Addlibs Posted January 12, 2016 Share Posted January 12, 2016 callRemote("http://*****/login.php", function (...) outputDebugString( toJSON({...}) ) end ) What does the PHP return to the debugstring, in JSON? (use the code above temporarily) Link to comment
Ruzy Posted January 12, 2016 Author Share Posted January 12, 2016 callRemote("http://*****/login.php", function (...) outputDebugString( toJSON({...}) ) end ) What does the PHP return to the debugstring, in JSON? (use the code above temporarily) Already checked that, it returns nothing. Link to comment
Addlibs Posted January 12, 2016 Share Posted January 12, 2016 In that case your PHP might be erroneous Link to comment
Ruzy Posted January 12, 2016 Author Share Posted January 12, 2016 php code: <?php // PHP include 'mta_sdk.php'; // Correct path if you use a different one $servername = "localhost"; // Change these details $username = "forum"; // Change these details $password = "*****"; // Change these details $dbname = "forum"; // Change these details $table = "mvp_core_members"; $accountColumn = "name"; // change to "email" if you prefer logging in through email $conn = mysqli_connect($servername, $username, $password, $dbname); if (!$conn) { mta::doReturn(false, "Connection failed: " . mysqli_connect_error()); // Account not found #die("Connection failed: " . mysqli_connect_error()); } $input = mta::getInput(); if (isset($input[0]) && isset($input[1]) && isset($input[2]) && $input[0] == "verifyPasswords" ) { $sql = "SELECT `member_id`, `member_group_id`, `members_pass_salt`, `members_pass_hash` FROM `".$table."` WHERE `".$accountColumn."`='".strtolower($input[1])."' LIMIT 1"; $result = mysqli_query($conn, $sql); if (mysqli_num_rows($result) > 0) { $row = mysqli_fetch_assoc($result); if (crypt($input[2], '$2a$13$' . $row['members_pass_salt']) == $row['members_pass_hash']) { mta::doReturn(true, 0, $row, $input[3], $input[1], $input[2]); // Password correct } else { mta::doReturn(false, 1, $row, $input[3]); // Passwords don't match } } else { mta::doReturn(false, 2, $row, $input[3]); // Account not found } } // Author: MrTasty ?> Link to comment
Ruzy Posted January 13, 2016 Author Share Posted January 13, 2016 The php is good, right? I used your php code as you can see. Edit: Also got a problem with the source! Link to comment
Addlibs Posted January 13, 2016 Share Posted January 13, 2016 I believe your primary problem might be caused by the fact you can't (I think) pass MTA elements into PHP, whilst you're trying to send the player element and return it back on callback. Link to comment
Ruzy Posted January 13, 2016 Author Share Posted January 13, 2016 How else should i set the source and get the userName then? i have tried many ways. because callremote is triggering another function it can't get the source, so i used callremote to return it Link to comment
Addlibs Posted January 13, 2016 Share Posted January 13, 2016 You can use coroutines to pause the thread while waiting for results (I don't really know how to make a code like that but I saw a few resources that employ this method) Link to comment
ALw7sH Posted January 13, 2016 Share Posted January 13, 2016 Use fetchRemote instead? I don't use callremote so I don't know about your problem but fetchRemote works fine the whole time for me (I mean you'll be able to pass the player element and the other things) And use echo "false"; and echo "true"; instead of mta::doReturn Link to comment
Ruzy Posted January 24, 2016 Author Share Posted January 24, 2016 I tried using fetchRemote , but now getting a error that the username or password are invalid. Code: <?php $dbHost = "***"; $dbUser = "forum"; $dbPass = "***"; $dbDB = "forum"; $dbTable = "core_members"; $dbAccount = "name"; $input = json_decode(file_get_contents("php://input"), true); if(is_array($input)): $dbCon = new PDO(sprintf("mysql:dbname=%s;host=%s;cahrset=utf8", $dbDB, $dbHost), $dbUser, $dbPass); if($dbCon): try { $sql= "SELECT `member_id`, `member_group_id`, `members_pass_hash`, `members_pass_salt` FROM `".$dbTable."` WHERE `".$dbAccount."`= '?' LIMIT 1"; $stmt = $dbCon->prepare($sql); $stmt->execute(array($input[0])); $result = $stmt->fetch(PDO::FETCH_ASSOC); if (crypt($input[1], '$2a$13$' . $result["members_pass_salt"]) == $result["members_pass_hash"]): echo sprintf('[ [ "succes", %d, %d ] ]', $result["member_id"], $result["memer_group_id"]); else: echo '[ [ "invalid" ] ]'; endif; } catch(PDOException $e) { } endif; $dbCon = NULL; endif; ?> function PlayerLogin(strUsername, strPassword, checksave) if not (strUsername == "") then if not (Password == "") then triggerClientEvent(source,"showNotification",getRootElement(), "Loging In...", "information") fetchRemote("[link]", 10, CheckLoginCallback, ('["%s","%s"]'):format(strUsername, strPassword), false, source, strUsername, strPassword, checksave) else triggerClientEvent(source,"showNotification",getRootElement(), "Please enter your password!", "error") end else triggerClientEvent(source,"showNotification",getRootElement(), "Please enter your username!", "error") end end addEvent("playerWantToLogin",true) addEventHandler("playerWantToLogin",getRootElement(),PlayerLogin) function CheckLoginCallback(strResponseData, iError, uPlayer, strUsername, strPassword, checksave) if(not isElement(uPlayer)) then return; end if(strResponseData == "ERROR") then triggerClientEvent(uPlayer,"showNotification",getRootElement(), "Unable to Log In (Failed to contact Server) (Error: " .. iError .. ")", "error") return; end local tblResult = fromJSON(strResponseData); if(tblResult[1] == "invalid" or tblResult[1] == "system") then if(tblResult[1] == "invalid") then triggerClientEvent(uPlayer,"showNotification",getRootElement(), "Invalid username or password specified!", "error") else triggerClientEvent(uPlayer,"showNotification",getRootElement(), "Unable to Log In! (System " ..tblResult[2] .. ")", "error") end elseif(tblResult[1] == "succes") then if checksave == true then triggerClientEvent(uPlayer,"saveLoginToXML",getRootElement(),strUsername,strPassword) else triggerClientEvent(uPlayer,"resetSaveXML",getRootElement(),strUsername,strPassword) end setElementData(uPlayer,"getForumID",tblResult[2]) setElementData(uPlayer,"getForumName",strUsername) triggerClientEvent(uPlayer,"showNotification",getRootElement(), "Successfully logged in!", "success") triggerClientEvent(uPlayer,"loginHide",getRootElement()) end end Link to comment
ALw7sH Posted January 24, 2016 Share Posted January 24, 2016 Does the MySQL return the account information? Link to comment
Castillo Posted January 24, 2016 Share Posted January 24, 2016 How else should i set the source and get the userName then? i have tried many ways. because callremote is triggering another function it can't get the source, so i used callremote to return it You could instead, send the serial of the player, and create a function to get the player element from the serial. Link to comment
BobbyJones Posted January 24, 2016 Share Posted January 24, 2016 I'm new here so maybe there is something I do not know but why use php for the login server instead of lua? Lua would make it easier to figure the stuff out. Link to comment
Ruzy Posted January 24, 2016 Author Share Posted January 24, 2016 Does the MySQL return the account information? It didn't return it. You could instead, send the serial of the player, and create a function to get the player element from the serial. That might be working too, gonna try it out. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now