FlyingSpoon Posted January 6, 2016 Share Posted January 6, 2016 (edited) Error(s) Outputted: When someone tries to login... Line 40: "Expected player at argument 1, got nil" Also when someone does press the login it makes the other players login as well! LUA CODE addEvent("playerWantToLogin",true) addEventHandler("playerWantToLogin",root, function(userName,Password) if not (userName == "") then if not (Password == "") then callRemote("[LINK]", function(response, extra, player, userName, Password) if response == true then checkLoginCallback("success", player, userName, Password) outputDebugString("Succesfully logged in (MySQL)!") else if extra == 1 then outputDebugString(toJSON({"Wrong Password!"})) elseif extra == 2 then outputDebugString(toJSON({"User doesnt exist!"})) end end end, "verifyPasswords", source, userName, Password) else outputChatBox("** Please enter your password! **", source, 191, 99, 0 ) end else outputChatBox("** Please enter your Username! **", source, 191, 99, 0 ) end end) function checkLoginCallback(gAccount, player, userName, Password) if gAccount == "success" then if not getAccount (userName) then acc = addAccount(tostring(userName),tostring(Password)) end if not getAccount(userName,Password) then setAccountPassword(getAccount(userName),Password) end local acc = getAccount ( userName,Password) if(not isGuestAccount(acc)) then logOut(player); end logIn (player, acc, Password) triggerClientEvent("loginHide", getRootElement()) outputChatBox("** You have logged in! **", player, 191, 99, 0 ) end end PHP CODE <?php // PHP include 'mta_sdk.php'; // Correct path if you use a different one $servername = "localhost"; // Change these details $username = "**********"; // Change these details $password = "**********"; // Change these details $dbname = "**********"; // 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[2]) && isset($input[3]) && $input[0] == "verifyPasswords" ) { $sql = "SELECT `members_pass_salt`, `members_pass_hash` FROM `".$table."` WHERE `".$accountColumn."`='".strtolower($input[2])."' LIMIT 1"; $result = mysqli_query($conn, $sql); if (mysqli_num_rows($result) > 0) { $row = mysqli_fetch_assoc($result); if (crypt($input[3], '$2a$13$' . $row['members_pass_salt']) == $row['members_pass_hash']) { mta::doReturn(true, 0, $input[1], $input[2], $input[3]); // Password correct } else { mta::doReturn(false, 1); // Passwords don't match } } else { mta::doReturn(false, 2); // Account not found } } // Author: MrTasty ?> Edited January 6, 2016 by Guest Link to comment
Revolt Posted January 6, 2016 Share Posted January 6, 2016 You cannot pass elements to PHP, and frankly, I don't think you need to. Remove the player argument from your function, and use source instead. Link to comment
KariiiM Posted January 28, 2016 Share Posted January 28, 2016 Also, PHP code must be scripted in server side. 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