Jump to content

MySQL login not working


thegergo02

Recommended Posts


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
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
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...