Firespider Posted March 6 Share Posted March 6 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 ) Link to comment
Firespider Posted March 6 Author Share Posted March 6 Thanks, does this still work, is the player's password encoded in sha512? Link to comment
Firespider Posted March 6 Author Share Posted March 6 So should I use this function to encrypt the password? Sorry to ask so many questions, but I'm new to this. @WWW Link to comment
Firespider Posted March 6 Author Share Posted March 6 (edited) So I encrypted the password local Pass = hash("sha512", pass) Should I replace it with this one now? sha256(pass) Edited March 6 by Firespider Link to comment
Firespider Posted March 9 Author Share Posted March 9 Doesn't Working i have a same problem Link to comment
Flashmyname Posted March 9 Share Posted March 9 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 Link to comment
FlorinSzasz Posted March 9 Share Posted March 9 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) Link to comment
Firespider Posted March 10 Author Share Posted March 10 (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 by Firespider Link to comment
WWW Posted March 10 Share Posted March 10 if sha256(pass) == result[1]["password"] then print("Sikeres bejelentkezés!") else print("Hibás jelszó!") end Link to comment
Firespider Posted March 10 Author Share Posted March 10 This problem is that one encrypted text is shorter than the other and so it is not the same what to do with it Link to comment
WWW Posted March 10 Share Posted March 10 Add a larger column to the database: VARCHAR(64) 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