thegergo02 Posted October 31, 2017 Share Posted October 31, 2017 function _Login(thePlayer,username,password) if username and exports.tp_sql:_QuerySingle("select username from users where username = ? ",username) then if password and exports.tp_sql:_QuerySingle("select password from users where username = ? ",username) == sha256(password) then token = generateToken(35) outputChatBox( token ) user_id = exports.tp_sql:_QuerySingle("select id from users where username = ? ",username) outputChatBox(user_id) exports.tp_sql:_Exec("insert into login_tokens(token,user_id) values (?,?)",token,user_id) setElementData(thePlayer,'reglog:token',sha256(token)) outputChatBox(getElementData(thePlayer,'reglog:token',token)) outputChatBox(getElementData(thePlayer,'reglog:token',sha256(token))) return 'login:successful' else return 'login:failed:password' end else return 'login:failed:username' end end Hi! I don't know why (the username IS IN the database) but the code give me 'login:failed:username'. Link to comment
MIKI785 Posted October 31, 2017 Share Posted October 31, 2017 (edited) I guess it depends on what does _QuerySingle look like Send us that code. Edited October 31, 2017 by MIKI785 1 Link to comment
thegergo02 Posted November 1, 2017 Author Share Posted November 1, 2017 (edited) When I am at home I send it. Edited November 1, 2017 by thegergo02 Link to comment
thegergo02 Posted November 1, 2017 Author Share Posted November 1, 2017 function _QuerySingle(str,...) if connection then local result = _Query(str,...) if type(result) == 'table' then return result[1] end else return false end end function _Exec(str,...) if connection then local query = dbExec(connection,str,...) return query else return false end end Link to comment
thegergo02 Posted November 2, 2017 Author Share Posted November 2, 2017 function _Login(username,password,thePlayer) outputChatBox( username ) outputChatBox( password ) if username and exports.tp_sql:_QuerySingle("select username from users where username = ? ",username) then if password and exports.tp_sql:_QuerySingle("select password from users where username = ? ",username) == sha256(password) then token = generateToken(35) outputChatBox( token ) user_id = exports.tp_sql:_QuerySingle("select id from users where username = ? ",username) outputChatBox(user_id) exports.tp_sql:_Exec("insert into login_tokens(token,user_id) values (?,?)",token,user_id) setElementData(thePlayer,'reglog:token',sha256(token)) outputChatBox(getElementData(thePlayer,'reglog:token',token)) outputChatBox(getElementData(thePlayer,'reglog:token',sha256(token))) return 'login:successful' else return 'login:failed:password' end else return 'login:failed:username' end end I tried to fix it, now I got 'login:failed:password' Link to comment
ShayF2 Posted November 3, 2017 Share Posted November 3, 2017 Use an app called Solo Learn, for sql teachings, the class is short and fast. It tell's everything about sql. This might help you. SELECT password,username,user_id,token FROM users WHERE username = ? 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