Mr. Maxilian Posted July 29, 2019 Share Posted July 29, 2019 All hi. Help please... I receive the login and the password which is entered by the player at an entrance. How to me to check correctness of the password (it is necessary to make corrections)? --Client ... local rpn = guiGetText(show_PN) --player login local rpp = guiGetText(show_PP) --player password triggerServerEvent("PlayerCheck", getLocalPlayer(), getLocalPlayer(), rpn, rpp) ... --Server addEvent("PlayerCheck", true) function PlayerCheck(player, username, password) ip = getPlayerIP(source) qh_username = dbQuery(db, "SELECT * FROM accounts WHERE username=?", username) local result_username = dbPoll(qh_username, -1) if #result_username >= 1 then qh_password = dbQuery(db, "SELECT password FROM accounts WHERE username=?", username) local result_password = dbPoll(qh_password, -1) if #result_password >= 1 then ... else triggerClientEvent(player, "error_password", root) end else triggerClientEvent(player, "error_username", root) end end addEventHandler("PlayerCheck", root, PlayerCheck) Link to comment
HassoN Posted July 29, 2019 Share Posted July 29, 2019 You basically just use: logIn with the entered information, and if the function returns false, then either the password or the username is wrong, and if it returns true then everything is fine. Example: check = logIn(source, username, password) if (check) then outputChatBox("Welcome", source) else outputChatBox("Either your password or username is wrong", source) end Link to comment
Mr. Maxilian Posted July 29, 2019 Author Share Posted July 29, 2019 57 minutes ago, HassoN said: You basically just use: logIn with the entered information, and if the function returns false, then either the password or the username is wrong, and if it returns true then everything is fine. Example: check = logIn(source, username, password) if (check) then outputChatBox("Welcome", source) else outputChatBox("Either your password or username is wrong", source) end Does not fit. I use mysql plugin Link to comment
HassoN Posted July 29, 2019 Share Posted July 29, 2019 (edited) 1 hour ago, Mr. Maxilian said: Does not fit. I use mysql plugin Ah, so you want to compare the entered password, username with your SQL value? Then: for _, row in ipairs ( result_password ) do if row["password"] == password then -- row["password"] depends on the name of the column in your database. outputChatBox("Correct password.") end end Edited July 29, 2019 by HassoN Link to comment
Moderators IIYAMA Posted July 29, 2019 Moderators Share Posted July 29, 2019 (edited) local selection = dbQuery(db, "SELECT * FROM accounts WHERE username=? AND password=? LIMIT 1", username, password) P.s. you shouldn't never save un-hashed passwords in the database. Yet, one step at the time. Edited July 29, 2019 by IIYAMA 1 Link to comment
Mr. Maxilian Posted July 29, 2019 Author Share Posted July 29, 2019 1 hour ago, IIYAMA said: local selection = dbQuery(db, "SELECT * FROM accounts WHERE username=? AND password=? LIMIT 1", username, password) local account = selection[1] if account then P.s. you shouldn't never save un-hashed passwords in the database. Yet, one step at the time. I need to check at first whether there is such login, and then only the right password or not. (Not at the same time) Link to comment
Moderators IIYAMA Posted July 29, 2019 Moderators Share Posted July 29, 2019 4 minutes ago, Mr. Maxilian said: I need to check at first whether there is such login, and then only the right password or not. (Not at the same time) Ah yea. (and I also wrote a wrong example. ops sorry) How about something like this? if type(username) == "string" and type(password) == "string" then local qh_account = dbQuery(db, "SELECT * FROM accounts WHERE username=? LIMIT 1", username) local result_account = dbPoll(qh_account, -1)[1] if result_account then if result_account.password == password then -- success else -- wrong password end else -- wrong username end end 1 Link to comment
Mr. Maxilian Posted July 29, 2019 Author Share Posted July 29, 2019 4 minutes ago, IIYAMA said: Ah yea. (and I also wrote a wrong example. ops sorry) How about something like this? if type(username) == "string" and type(password) == "string" then local qh_account = dbQuery(db, "SELECT * FROM accounts WHERE username=? LIMIT 1", username) local result_account = dbPoll(qh_account, -1)[1] if result_account then if result_account.password == password then -- success else -- wrong password end else -- wrong username end end Correctly? addEvent("PlayerCheck", true) function PlayerCheck(player, username, password) if type(username) == "string" and type(password) == "string" then local qh_account = dbQuery(db, "SELECT * FROM accounts WHERE username=? LIMIT 1", username) local result_account = dbPoll(qh_account, -1)[1] if result_account then if result_account.password == password then-- success else-- wrong password end else-- wrong username end end end addEventHandler("PlayerCheck", root, PlayerCheck) 1 Link to comment
Moderators IIYAMA Posted July 29, 2019 Moderators Share Posted July 29, 2019 @Mr. Maxilian Afaik yes, but you still need to (manually) debug it in order to figure out it is 100% working. As being a human I can overlook things after all. 1 Link to comment
Mr. Maxilian Posted July 29, 2019 Author Share Posted July 29, 2019 1 minute ago, IIYAMA said: @Mr. Maxilian Afaik yes, but you still need to (manually) debug it in order to figure out it is 100% working. As being a human I can overlook things after all. 10 line. Unexpected symbol near ' ' Link to comment
Moderators IIYAMA Posted July 29, 2019 Moderators Share Posted July 29, 2019 (edited) 8 minutes ago, Mr. Maxilian said: 10 line. Unexpected symbol near ' ' It seems like you copied some wrong (invisible) characters in to your code. (can happen with the forum text editor, not sure what the issue is) I cleaned it for you. addEvent("PlayerCheck", true) function PlayerCheck(player, username, password) if type(username) == "string" and type(password) == "string" then local qh_account = dbQuery(db, "SELECT * FROM accounts WHERE username=? LIMIT 1", username) local result_account = dbPoll(qh_account, -1)[1] if result_account then if result_account.password == password then else end else end end end addEventHandler("PlayerCheck", root, PlayerCheck) Edited July 29, 2019 by IIYAMA 1 Link to comment
Mr. Maxilian Posted July 29, 2019 Author Share Posted July 29, 2019 11 minutes ago, IIYAMA said: It seems like you copied some wrong (invisible) characters in to your code. (can happen with the forum text editor, not sure what the issue is) I cleaned it for you. addEvent("PlayerCheck", true) function PlayerCheck(player, username, password) if type(username) == "string" and type(password) == "string" then local qh_account = dbQuery(db, "SELECT * FROM accounts WHERE username=? LIMIT 1", username) local result_account = dbPoll(qh_account, -1)[1] if result_account then if result_account.password == password then else end else end end end addEventHandler("PlayerCheck", root, PlayerCheck) Thanks! Everything works. 1 Link to comment
Mr. Maxilian Posted July 29, 2019 Author Share Posted July 29, 2019 43 minutes ago, IIYAMA said: It seems like you copied some wrong (invisible) characters in to your code. (can happen with the forum text editor, not sure what the issue is) I cleaned it for you. addEvent("PlayerCheck", true) function PlayerCheck(player, username, password) if type(username) == "string" and type(password) == "string" then local qh_account = dbQuery(db, "SELECT * FROM accounts WHERE username=? LIMIT 1", username) local result_account = dbPoll(qh_account, -1)[1] if result_account then if result_account.password == password then else end else end end end addEventHandler("PlayerCheck", root, PlayerCheck) Prompt how for example to receive quantity of money from the field "money" and to issue them to the player? Link to comment
Moderators IIYAMA Posted July 29, 2019 Moderators Share Posted July 29, 2019 2 minutes ago, Mr. Maxilian said: Prompt how for example to receive quantity of money from the field "money" and to issue them to the player? If the money is stored on for example the column money then you could access it like this: local money = tonumber(result_account.money) if money then else -- something went really bad ;[ end If your mysql "money" column is not correctly set-up to already fill in the money as a 0. Then this is also an option: local money = tonumber(result_account.money) or 0 Link to comment
Mr. Maxilian Posted July 29, 2019 Author Share Posted July 29, 2019 17 minutes ago, IIYAMA said: If the money is stored on for example the column money then you could access it like this: local money = tonumber(result_account.money) if money then else -- something went really bad ;[ end If your mysql "money" column is not correctly set-up to already fill in the money as a 0. Then this is also an option: local money = tonumber(result_account.money) or 0 Thanks! Everything works. 1 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