Firespider Posted March 6, 2024 Posted March 6, 2024 Hello, I have a problem when logging in. I try to see if the hashed password in the database is the same as the one entered by the player for the password, so I check if the password is correct. But even if you enter a good password and the two passwords are the same, the system always says that the password is incorrect. Can you help? addEvent("login", true) addEventHandler("login", root, function (user, pass) local serial = getPlayerSerial(client) local dq = dbQuery(db, "SELECT * FROM accounts WHERE serial=?", serial) local result = dbPoll(dq, 250) if (#result > 0) then outputChatBox(pass) local Pass = hash("sha512", pass) outputChatBox(Pass) if user == result[1]["username"] then if Pass == result[1]["password"] then print("Sikeres bejelentkezés!") else print("Hibás jelszó!") end else print("Felhasználónév nem található!") end else print("Sikertelen bejelentkezés!") end end )
Firespider Posted March 6, 2024 Author Posted March 6, 2024 Thanks, does this still work, is the player's password encoded in sha512?
Firespider Posted March 6, 2024 Author Posted March 6, 2024 So should I use this function to encrypt the password? Sorry to ask so many questions, but I'm new to this. @WWW
Firespider Posted March 6, 2024 Author Posted March 6, 2024 (edited) So I encrypted the password local Pass = hash("sha512", pass) Should I replace it with this one now? sha256(pass) Edited March 6, 2024 by Firespider
Flashmyname Posted March 9, 2024 Posted March 9, 2024 It doesn't work just like that, you should define what a 'hash' is, and what should be applied to. for example if you wanna encrypt your password while typing it in, you should use it somehow like this one. if string.find(details, "hash") then if length > 0 then hash = string.rep("•", length) end end
FlorinSzasz Posted March 9, 2024 Posted March 9, 2024 1 hour ago, Firespider said: Doesn't Working i have a same problem local result = dbPoll(dq,250) -- this should --be like this local result = dbPoll(dq,-1) --Also is result[1]["password"] encrypted? when you insert it into the database? passwordVerify(pass,result[1]["password"]) --------------------------------------------------- addEvent("login", true) addEventHandler("login", root, function (user, pass) local serial = getPlayerSerial(client) local dq = dbQuery(db, "SELECT * FROM accounts WHERE serial=?", serial) local result = dbPoll(dq,-1) if (#result > 0) then if user == result[1]["username"] then if (passwordVerify(pass,result[1]["password"])) then print("Sikeres bejelentkezés!") else print("Hibás jelszó!") end else print("Felhasználónév nem található!") end else print("Sikertelen bejelentkezés!") end end)
Firespider Posted March 10, 2024 Author Posted March 10, 2024 (edited) That's the problem, I'll send the whole server page to see if it helps addEvent("register", true) addEventHandler("register", root, function (user, pass, repass) local serial = getPlayerSerial(client) local dq = dbQuery(db, "SELECT * FROM accounts WHERE serial=?", serial) local result = dbPoll(dq, 250) local HashPass = sha256(pass) if (#result > 0) then print("NODUPLACITEACC") else dbExec(db, "INSERT INTO accounts (username, password, serial) VALUES (?, ?, ?)", user, HashPass, serial) end end ) addEvent("login", true) addEventHandler("login", root, function (user, pass) local serial = getPlayerSerial(client) local dq = dbQuery(db, "SELECT * FROM accounts WHERE serial=?", serial) local result = dbPoll(dq,250) if (#result > 0) then if user == result[1]["username"] then if (passwordVerify(pass,result[1]["password"])) then print("Sikeres bejelentkezés!") else print("Hibás jelszó!") end else print("Felhasználónév nem található!") end else print("Sikertelen bejelentkezés!") end end) Edited March 10, 2024 by Firespider
WWW Posted March 10, 2024 Posted March 10, 2024 if sha256(pass) == result[1]["password"] then print("Sikeres bejelentkezés!") else print("Hibás jelszó!") end
Firespider Posted March 10, 2024 Author Posted March 10, 2024 This problem is that one encrypted text is shorter than the other and so it is not the same what to do with it
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