Jump to content

Problem sql


Dimos7

Recommended Posts

setCameraMatrix(-2065.0327148438, 1021.1545410156, 66.882278442383, -2117.1064453125, 1106.4571533203, 70.316734313965)
setPlayerHudComponentVisible("all", false)

local wLogin, lUser, lPass, eUser, ePass, bLogin, bRegister, cRemeber = nil
local wPass, lPass, lRpass, ePasw, eRpass, bPass, bCancel = nil

function createPasswordWindow()
    local screenWidth, screenHeight = guiGetScreenSize()
	local windowWidth , windowHeiht = 458, 347
	local left , top = screenWidth/2 - windowWidth/2, screenHeight/2 - windowHeiht/2
	wPass = guiCreateWindow(left, top, windowWidth, windowHeiht, "Change Password", false)
	guiWindowSetMovable(wPass, false)
	guiWindowSetSizable(wPass, false)
	lPass = guiCreateLabel(23, 46, 96, 18, "Password:", false, wPass)
	guiLabelSetHorizontalAlign(lPass, "left")
	guiLabelSetVerticalAlign(lPass, "top")
	ePasw = guiCreateEdit(137, 46, 287, 33, "", false, wPass)
	guiEditSetMasked(ePasw, true)
	lRpass = guiCreateLabel(23, 132, 96, 18, "Repeat Password:", false, wPass)
	guiLabelSetHorizontalAlign(lRpass, "left")
	guiLabelSetVerticalAlign(lPass, "top")
	eRpass = guiCreateEdit(137, 132, 287, 33, "", false, wPass)
	guiEditSetMasked(eRpass, true)
	bPass = guiCreateButton(42, 273, 128, 37, "Change", false, wPass)
	bCancel = guiCreateButton(253, 273, 128, 37, "Cancel", false, wPass)
	guiSetVisible(wPass, false)
	addEventHandler("onClientGUIClick", bPass, onClientSubmitChangePw)
	addEventHandler("onClientGUIClick", bCancel, hidePasswordWindow)
end

function createLoginWindow()
     local screenWidth, screenHeight = guiGetScreenSize()
	 local windowWidth, windowHeiht = 458, 347
	 local left, top = screenWidth/2 - windowWidth/2, screenHeight/2 - windowHeiht/2
	 wLogin = guiCreateWindow(left, top, windowWidth, windowHeiht, "Login Panel", false)
	 guiWindowSetMovable(wLogin, false)
	 guiWindowSetSizable(wLogin, false)
	 lUser = guiCreateLabel(23, 46, 96, 18, "Username:", false, wLogin)
	 guiLabelSetHorizontalAlign(lUser, "left")
	 guiLabelSetVerticalAlign(lUser, "top")
	 eUser = guiCreateEdit(137, 46, 287, 33, "", false, wLogin)
	 lPass = guiCreateLabel(23, 132, 96, 18, "Password:", false, wLogin)
	 guiLabelSetHorizontalAlign(lPass, "left")
	 guiLabelSetVerticalAlign(lPass, "top")
	 ePass = guiCreateEdit(137, 132, 287, 33, "", false, wLogin)
	 guiEditSetMasked(ePass, true)
	 bLogin = guiCreateButton(42, 273, 128, 37, "Login", false, wLogin)
	 bRegister = guiCreateButton(253, 273, 128, 37, "Register", false, wLogin)
	 addEventHandler("onClientGUIClick", bLogin, onClientSubmitLogin)
	 addEventHandler("onClientGUIClick", bRegister, onClientSubmitRegister)
end

function resourceStart()
    createLoginWindow()
    if wLogin ~= nil then
	   guiSetVisible(wLogin, true)
	else
	   outputChatBox("An error has been occupied!", 255, 0, 0)
	end
	guiSetInputEnabled(true)
	showCursor(true)
end

function onClientSubmitChangePw(button , state)
    if button == "left" and state == "up" then
	    local password = guiGetText(ePasw)
		local rpassword= guiGetText(eRpass)
		if password ~= "" and rpassword ~= "" then
		   triggerServerEvent("submitChangepw", root, localPlayer, password, rpassword)
		else
		   outputChatBox("Enter password and Repeat it!", 255, 0, 0)
		end
	end
end

function onClientSubmitLogin(button, state)
    if button == "left" and state == "up" then
	   local username = guiGetText(eUser)
	   local password = guiGetText(ePass)
	   if username ~= "" and password ~= "" then
	      triggerServerEvent("submitLogin", root, localPlayer, username, password)
	   else
	      outputChatBox("Enter username and password!", 255, 0, 0)
	   end
	end
end

function onClientSubmitRegister(button, state)
    if button == "left" and state == "up" then
	   local username = guiGetText(eUser)
	   local password = guiGetText(ePass)
	   if username ~= "" and password ~= "" then
	      triggerServerEvent("submitRegister", root, localPlayer, username, password)
	   else
	      outputChatBox("Enter username and password!", 255, 0, 0)
	   end
	end
end

function changepw()
    createPasswordWindow()
    guiSetVisible(wPass, true)
	showCursor(true)
	guiSetInputEnabled(true)
end

function hidePasswordWindow()
    guiSetVisible(wPass, false)
	showCursor(false)
	guiSetInputEnabled(false)
	setCameraTarget(localPlayer)
	setPlayerHudComponentVisible("all", true)
end

function hideLoginWindow()
    guiSetVisible(wLogin, false)
	guiSetInputEnabled(false)
	showCursor(false)
	setCameraTarget(localPlayer)
	setPlayerHudComponentVisible("all", true)
end

addEvent("hidePasswordWindow", true)
addEvent("hideLoginWindow", true)
addEventHandler("hidePasswordWindow", root, hidePasswordWindow)
addEventHandler("hideLoginWindow", root, hideLoginWindow)
addEventHandler("onClientResourceStart", resourceRoot, resourceStart)
addCommandHandler("chagepass", changepw)
addEventHandler("onResourceStart", resourceRoot, 
   function()
          handler = mysql_connect("127.0.0.1", "root", "9852174563", "mtarace")
   end)
   
function passwordHandler(thePlayer, password, rpassword)
    local account = getPlayerAccount(thePlayer)
	if account then
	   if isGuestAccount(account) then
	      outputChatBox("Error: You must be logged in to change password!", thePlayer, 255, 0, 0)
	   end
	   if password == rpassword then
	      if string.len(password) >=5 then
		     setAccountPassword(account, password)
			 mysql_query(handler, "UPDATE accounts SET password='"..password.."'")
			 triggerClientEvent(thePlayer, "hidePasswordWindow", root)
		  else
		     outputChatBox("Error: You new password must be at least 5 character long!", thePlayer, 255, 0, 0)
		  end
	   else
	      outputChatBox("Error: Your passwords aren't the same!", thePlayer, 255, 0, 0)
	   end
	end
end

function loginHandler(thePlayer, username, password)
    local account = getAccount(username, password)
    local pname = mysql_escape_string(handler, username)
    local ppw = mysql_escape_string(handler, password)
    local query = "SELECT * FROM accounts WHERE username=\'"..pname.."\' and password=\'"..ppw.."\';"
    local result = mysql_query(handler, query)
    if account ~= false and result and mysql_num_rows(result) > 0 then
	    if (logIn(thePlayer, account, password) == true) then
		   triggerClientEvent(thePlayer, "hideLoginPassword", root)
		   outputChatBox("INFO: Welcome ".. getPlayerName(thePlayer) " you successfully logged in!", thePlayer, 0, 255, 0)
		else
		   outputChatBox("Error: please report it to forum!", thePlayer, 255, 0, 0)
	    end
	else
	   outputChatBox("Error: Username or password are incorrect!", thePlayer, 255, 0, 0)
    end
end

function registerHandler(thePlayer, username, password)
    local account = getAccount(username, password)
	local query = "SELECT * FROM accounts WHERE username=\'"..username.."\' and password=\'"..password.."\';"
	local result = mysql_query(handler, query)
	if account ~= false and result and mysql_num_rows(result) > 0 then
	   outputChatBox("Username already exist!", thePlayer, 255, 0, 0)
	else
	   account = addAccount(username, password)
	   outputChatBox("INFO: you successfully register!", thePlayer, 0, 255, 0)
	   local pname = mysql_escape_string(handler, username)
	   local ppw = mysql_escape_string(handler, password)
	   local time = getRealTime()
	   local years = time.year
	   local months = time.month
	   local monthdays = time.monthday
	   local hours = time.hour
	   local minutes = time.minute
	   local seconds = time.second
	   local years2 = years+1900
	   local months2 = months+1
	   local alltogether = years2.."-"..months2.."-"..monthdays.." "..hours..":"..minutes..":"..seconds
	   local result = mysql_query(handler, "INSERT INTO accounts (username, password, ip, srial, registerDate) VALUES (username='"..pname.."',password='"..ppw.."', ip='"..getPlayerIP(thePlayer).."', serial='"..getPlayerSerial(thePlayer).."', registerDate='"..alltogether.."')")
	end
end

addEvent("submitChangepw", true)
addEvent("submitLogin", true)
addEvent("submitRegister", true)
addEventHandler("submitChangepw", root, passwordHandler)
addEventHandler("submitLogin", root, loginHandler)
addEventHandler("submitRegister", root, registerHandler)

code work put not register the account at mysql dabase etc all right it register account at acl

Edited by Dimos7
Link to comment
function registerHandler(thePlayer, username, password)
  	local account = getAccount(username, password)
    	-- you need this
  	username = mysql_escape_string(handler, username)
        password = mysql_escape_string(handler, username)
    	-- because i can put in password string "';[My Custom SQL Query been execute, lol]'"
	local query = "SELECT * FROM accounts WHERE username=\'"..username.."\' and password=\'"..password.."\';"
	local result = mysql_query(handler, query)
 	-- ...
end

in 65 line you have

"INSERT INTO accounts (username, password, ip, srial, registerDate) ..."

srial? maybe "serial"

Edited by cacao
  • Like 1
Link to comment
addEventHandler("onResourceStart", resourceRoot, 
   function()
          handler = mysql_connect("127.0.0.1", "root", "9852174563", "mtarace")
   end)
   
function passwordHandler(thePlayer, password, rpassword)
    local account = getPlayerAccount(thePlayer)
	if account then
	   if isGuestAccount(account) then
	      outputChatBox("Error: You must be logged in to change password!", thePlayer, 255, 0, 0)
	   end
	   if password == rpassword then
	      if string.len(password) >=5 then
		     setAccountPassword(account, password)
			 mysql_query(handler, "UPDATE accounts SET password='"..mysql_escape_string(password).."' WHERE username='"..mysql_escape_string(account).."'")
			 triggerClientEvent(thePlayer, "hidePasswordWindow", root)
		  else
		     outputChatBox("Error: You new password must be at least 5 character long!", thePlayer, 255, 0, 0)
		  end
	   else
	      outputChatBox("Error: Your passwords aren't the same!", thePlayer, 255, 0, 0)
	   end
	end
end

function loginHandler(thePlayer, username, password)
    local account = getAccount(username, password)
    local pname = mysql_escape_string(handler, username)
    local ppw = mysql_escape_string(handler, password)
    local query = "SELECT * FROM accounts WHERE username=\'"..pname.."\' and password=\'"..ppw.."\';"
    local result = mysql_query(handler, query)
    if account ~= false and result and mysql_num_rows(result) > 0 then
	    if (logIn(thePlayer, account, password) == true) then
		   triggerClientEvent(thePlayer, "hideLoginPassword", root)
		   outputChatBox("INFO: Welcome ".. getPlayerName(thePlayer) " you successfully logged in!", thePlayer, 0, 255, 0)
		else
		   outputChatBox("Error: please report it to forum!", thePlayer, 255, 0, 0)
	    end
	else
	   outputChatBox("Error: Username or password are incorrect!", thePlayer, 255, 0, 0)
    end
end

function registerHandler(thePlayer, username, password)
    local account = getAccount(username, password)
	local query = "SELECT * FROM accounts WHERE username=\'"..username.."\' and password=\'"..password.."\';"
	local result = mysql_query(handler, query)
	if account ~= false and result and mysql_num_rows(result) > 0 then
	   outputChatBox("Username already exist!", thePlayer, 255, 0, 0)
	else
	   account = addAccount(username, password)
	   outputChatBox("INFO: you successfully register!", thePlayer, 0, 255, 0)
	   local name = mysql_escape_string(handler, username)
	   local pw = mysql_escape_string(handler, password)
	   local time = getRealTime()
	   local years = time.year
	   local months = time.month
	   local monthdays = time.monthday
	   local hours = time.hour
	   local minutes = time.minute
	   local seconds = time.second
	   local years2 = years+1900
	   local months2 = months+1
	   local alltogether = years2.."-"..months2.."-"..monthdays.." "..hours..":"..minutes..":"..seconds
	   local query = "INSERT INTO accounts  SET username='"..name.."',password='"..pw.."', ip='"..getPlayerIP(thePlayer).."', serial='"..getPlayerSerial(thePlayer).."', registerDate='"..alltogether.."'"
	   local result = mysql_query(handler, query)
	end
end

addEvent("submitChangepw", true)
addEvent("submitLogin", true)
addEvent("submitRegister", true)
addEventHandler("submitChangepw", root, passwordHandler)
addEventHandler("submitLogin", root, loginHandler)
addEventHandler("submitRegister", root, registerHandler)

same problem account in acl register not in sql and appear error that username or password are incorrect no error or warning in debugscript 3

 

Edited by Dimos7
Link to comment
addEventHandler("onResourceStart", resourceRoot, 
   function()
          handler = mysql_connect("127.0.0.1", "root", "9852174563", "mtarace")
   end)
   
function passwordHandler(thePlayer, password, rpassword)
    local account = getPlayerAccount(thePlayer)
	if account then
	   if isGuestAccount(account) then
	      outputChatBox("Error: You must be logged in to change password!", thePlayer, 255, 0, 0)
	   end
	   if password == rpassword then
	      if string.len(password) >=5 then
		     setAccountPassword(account, password)
			 mysql_query(handler, "UPDATE accounts SET password='"..mysql_escape_string(password).."' WHERE username='"..mysql_escape_string(account).."'")
			 triggerClientEvent(thePlayer, "hidePasswordWindow", root)
		  else
		     outputChatBox("Error: You new password must be at least 5 character long!", thePlayer, 255, 0, 0)
		  end
	   else
	      outputChatBox("Error: Your passwords aren't the same!", thePlayer, 255, 0, 0)
	   end
	end
end

function loginHandler(thePlayer, username, password)
    local account = getAccount(username, password)
    local pname = mysql_escape_string(handler, username)
    local ppw = mysql_escape_string(handler, password)
    local query = "SELECT * FROM accounts WHERE username='"..pname.."\' and password='"..ppw.."'"
    local result = mysql_query(handler, query)
    if account ~= false and result and mysql_num_rows(result) > 0 then
	    if (logIn(thePlayer, account, password) == true) then
		   triggerClientEvent(thePlayer, "hideLoginPassword", root)
		   outputChatBox("INFO: Welcome ".. getPlayerName(thePlayer) " you successfully logged in!", thePlayer, 0, 255, 0)
		else
		   outputChatBox("Error: please report it to forum!", thePlayer, 255, 0, 0)
	    end
	else
	   outputChatBox("Error: Username or password are incorrect!", thePlayer, 255, 0, 0)
    end
end

function registerHandler(thePlayer, username, password)
    local account = getAccount(username, password)
	local query = "SELECT * FROM accounts WHERE username='"..username.."' and password='"..password.."'"
	local result = mysql_query(handler, query)
	if account ~= false and result and mysql_num_rows(result) > 0 then
	   outputChatBox("Error: Username already exist!", thePlayer, 255, 0, 0)
	else
	   account = addAccount(username, password)
	   outputChatBox("INFO: you successfully register!", thePlayer, 0, 255, 0)
	   local name = mysql_escape_string(handler, username)
	   local pw = mysql_escape_string(handler, password)
	   local time = getRealTime()
	   local years = time.year
	   local months = time.month
	   local monthdays = time.monthday
	   local hours = time.hour
	   local minutes = time.minute
	   local seconds = time.second
	   local years2 = years+1900
	   local months2 = months+1
	   local alltogether = years2.."-"..months2.."-"..monthdays.." "..hours..":"..minutes..":"..seconds
	   local query = "INSERT INTO accounts SET username='"..name.."',password='"..pw.."', ip='"..getPlayerIP(thePlayer).."', serial='"..getPlayerSerial(thePlayer).."', registerDate='"..alltogether.."'"
	   local result = mysql_query(handler, query)
	end
end

addEvent("submitChangepw", true)
addEvent("submitLogin", true)
addEvent("submitRegister", true)
addEventHandler("submitChangepw", root, passwordHandler)
addEventHandler("submitLogin", root, loginHandler)
addEventHandler("submitRegister", root, registerHandler)

why account register at acl and no register at mysql

Link to comment
addEventHandler("onResourceStart", resourceRoot, 
   function()
          handler = dbConnect("mysql", "dbname=mtarace; host=127.0.0.1", "root", "9852174563")
   end)
   
function passwordHandler(thePlayer, password, rpassword)
    local account = getPlayerAccount(thePlayer)
	if account then
	   if isGuestAccount(account) then
	      outputChatBox("Error: You must be logged in to change password!", thePlayer, 255, 0, 0)
	   end
	   if password == rpassword then
	      if string.len(password) >=5 then
		     setAccountPassword(account, password)
			 dbExec(handler, "UPDATE accounts SET password='"..tostring(password).."' WHERE username='"..tostring(account).."'")
			 triggerClientEvent(thePlayer, "hidePasswordWindow", root)
		  else
		     outputChatBox("Error: You new password must be at least 5 character long!", thePlayer, 255, 0, 0)
		  end
	   else
	      outputChatBox("Error: Your passwords aren't the same!", thePlayer, 255, 0, 0)
	   end
	end
end

function loginHandler(thePlayer, username, password)
    local account = getAccount(username, password)
    local pname = tostring(username)
    local ppw = tostring (password)
    local query = dbQuery(handler, "SELECT * FROM accounts WHERE username='"..pname.."' and password='"..ppw.."'")
    local result = dbPoll(query, - 1)
    if account ~= false and result > 0 then
	    if (logIn(thePlayer, account, password) == true) then
		   triggerClientEvent(thePlayer, "hideLoginPassword", root)
		   outputChatBox("INFO: Welcome ".. getPlayerName(thePlayer) " you successfully logged in!", thePlayer, 0, 255, 0)
		else
		   outputChatBox("Error: please report it to forum!", thePlayer, 255, 0, 0)
	    end
	else
	   outputChatBox("Error: Username or password are incorrect!", thePlayer, 255, 0, 0)
    end
end

function registerHandler(thePlayer, username, password)
    local account = getAccount(username, password)
	local query = dbQuery(handler,"SELECT * FROM accounts WHERE username='"..username.."' and password='"..password.."'")
	local result = dbPoll(query, -1)
	if account ~= false and result > 0 then
	   outputChatBox("Error: Username already exist!", thePlayer, 255, 0, 0)
	else
	   account = addAccount(username, password)
	   outputChatBox("INFO: you successfully register!", thePlayer, 0, 255, 0)
	   local name = tostring(username)
	   local pw = tostring(password)
	   local time = getRealTime()
	   local years = time.year
	   local months = time.month
	   local monthdays = time.monthday
	   local hours = time.hour
	   local minutes = time.minute
	   local seconds = time.second
	   local years2 = years+1900
	   local months2 = months+1
	   local alltogether = years2.."-"..months2.."-"..monthdays.." "..hours..":"..minutes..":"..seconds
	   dbExec(handler, "INSERT INTO accounts (username, password, ip, serial, registerDate) VALUES(username='"..name.."',password='"..pw.."', ip='"..getPlayerIP(thePlayer).."', serial='"..getPlayerSerial(thePlayer).."', registerDate='"..alltogether.."')")
	end
end

addEvent("submitChangepw", true)
addEvent("submitLogin", true)
addEvent("submitRegister", true)
addEventHandler("submitChangepw", root, passwordHandler)
addEventHandler("submitLogin", root, loginHandler)
addEventHandler("submitRegister", root, registerHandler)

warning line 65 dbExec failed 1054 unknown column username

http://imgur.com/V2MvZnJ

Edited by Dimos7
Link to comment

The error was, that you had the field name as userrname, with double 'r', but you know that already. Just a tip: see when you are checking if there is a user already registered with the username? You should remove the password part from the where clause, because it makes no sense. That would mean two different users would be able to register with the same name but different passwords... I'm sure that's not what you want.

Link to comment
setCameraMatrix(-2065.0327148438, 1021.1545410156, 66.882278442383, -2117.1064453125, 1106.4571533203, 70.316734313965)
setPlayerHudComponentVisible("all", false)

local wLogin, lUser, lPass, eUser, ePass, bLogin, bRegister, cRemeber = nil
local wPass, lPass, lRpass, ePasw, eRpass, bPass, bCancel = nil

function createPasswordWindow()
    local screenWidth, screenHeight = guiGetScreenSize()
	local windowWidth , windowHeiht = 458, 347
	local left , top = screenWidth/2 - windowWidth/2, screenHeight/2 - windowHeiht/2
	wPass = guiCreateWindow(left, top, windowWidth, windowHeiht, "Change Password", false)
	guiWindowSetMovable(wPass, false)
	guiWindowSetSizable(wPass, false)
	lPass = guiCreateLabel(23, 46, 96, 18, "Password:", false, wPass)
	guiLabelSetHorizontalAlign(lPass, "left")
	guiLabelSetVerticalAlign(lPass, "top")
	ePasw = guiCreateEdit(137, 46, 287, 33, "", false, wPass)
	guiEditSetMasked(ePasw, true)
	lRpass = guiCreateLabel(23, 132, 96, 18, "Repeat Password:", false, wPass)
	guiLabelSetHorizontalAlign(lRpass, "left")
	guiLabelSetVerticalAlign(lPass, "top")
	eRpass = guiCreateEdit(137, 132, 287, 33, "", false, wPass)
	guiEditSetMasked(eRpass, true)
	bPass = guiCreateButton(42, 273, 128, 37, "Change", false, wPass)
	bCancel = guiCreateButton(253, 273, 128, 37, "Cancel", false, wPass)
	guiSetVisible(wPass, false)
	addEventHandler("onClientGUIClick", bPass, onClientSubmitChangePw)
	addEventHandler("onClientGUIClick", bCancel, hidePasswordWindow)
end

function createLoginWindow()
     local screenWidth, screenHeight = guiGetScreenSize()
	 local windowWidth, windowHeiht = 458, 347
	 local left, top = screenWidth/2 - windowWidth/2, screenHeight/2 - windowHeiht/2
	 wLogin = guiCreateWindow(left, top, windowWidth, windowHeiht, "Login Panel", false)
	 guiWindowSetMovable(wLogin, false)
	 guiWindowSetSizable(wLogin, false)
	 lUser = guiCreateLabel(23, 46, 96, 18, "Username:", false, wLogin)
	 guiLabelSetHorizontalAlign(lUser, "left")
	 guiLabelSetVerticalAlign(lUser, "top")
	 eUser = guiCreateEdit(137, 46, 287, 33, "", false, wLogin)
	 lPass = guiCreateLabel(23, 132, 96, 18, "Password:", false, wLogin)
	 guiLabelSetHorizontalAlign(lPass, "left")
	 guiLabelSetVerticalAlign(lPass, "top")
	 ePass = guiCreateEdit(137, 132, 287, 33, "", false, wLogin)
	 guiEditSetMasked(ePass, true)
	 bLogin = guiCreateButton(42, 273, 128, 37, "Login", false, wLogin)
	 bRegister = guiCreateButton(253, 273, 128, 37, "Register", false, wLogin)
	 cRemeber = guiCreateCheckBox(23, 215, 100, 15, "Remember me", false, false, wLogin)
	 addEventHandler("onClientGUIClick", cRemeber, onClientSaveInfo)
	 addEventHandler("onClientGUIClick", bLogin, onClientSubmitLogin)
	 addEventHandler("onClientGUIClick", bRegister, onClientSubmitRegister)
end

function resourceStart()
    createLoginWindow()
    if wLogin ~= nil then
	   guiSetVisible(wLogin, true)
	else
	   outputChatBox("Error: An error has been occupied!", 255, 0, 0)
	end
	guiSetInputEnabled(true)
	showCursor(true)
end

function onClientSubmitChangePw(button , state)
    if button == "left" and state == "up" then
	    local password = guiGetText(ePasw)
		local rpassword= guiGetText(eRpass)
		if password ~= "" and rpassword ~= "" then
		   triggerServerEvent("submitChangepw", root, localPlayer, password, rpassword)
		else
		   outputChatBox("Error: Enter password and Repeat it!", 255, 0, 0)
		end
	end
end

function onClientSubmitLogin(button, state)
    if button == "left" and state == "up" then
	   local username = guiGetText(eUser)
	   local password = guiGetText(ePass)
	   if username ~= "" and password ~= "" then
	      triggerServerEvent("submitLogin", root, localPlayer, username, password)
	   else
	      outputChatBox("Error: Enter username and password!", 255, 0, 0)
	   end
	end
end

function onClientSubmitRegister(button, state)
    if button == "left" and state == "up" then
	   local username = guiGetText(eUser)
	   local password = guiGetText(ePass)
	   if username ~= "" and password ~= "" then
	      triggerServerEvent("submitRegister", root, localPlayer, username, password)
	   else
	      outputChatBox("Error: Enter username and password!", 255, 0, 0)
	   end
	end
end

function onClientSaveInfo(button, state)
    if button == "left" and state == "up" then
	   if guiCheckBoxGetSelected(cRemeber) then
	      guiCheckBoxSetSelected(cRemeber, true)
		  if triggerServerEvent("submitLogin") then
		     if guiCheckBoxGetSelected(cRemeber) == true then
		        username = getElementData(localPlayer, "account:username")
			    password = getElementData(localPlayer, "account:password")
			    guiSetText(eUser, username)
			    guiSetText(ePass, password)
		     end
	     end
	  else
	     guiCheckBoxSetSelected(cRemeber, false)
	  end
	end
end


function changepw()
    createPasswordWindow()
    guiSetVisible(wPass, true)
	showCursor(true)
	guiSetInputEnabled(true)
end

function hidePasswordWindow()
    guiSetVisible(wPass, false)
	showCursor(false)
	guiSetInputEnabled(false)
	setCameraTarget(localPlayer)
	setPlayerHudComponentVisible("all", true)
end

function hideLoginWindow()
    guiSetVisible(wLogin, false)
	guiSetInputEnabled(false)
	showCursor(false)
	setCameraTarget(localPlayer)
	setPlayerHudComponentVisible("all", true)
end

addEvent("hidePasswordWindow", true)
addEvent("hideLoginWindow", true)
addEventHandler("hidePasswordWindow", root, hidePasswordWindow)
addEventHandler("hideLoginWindow", root, hideLoginWindow)
addEventHandler("onClientResourceStart", resourceRoot, resourceStart)
addCommandHandler("chagepass", changepw)
addEventHandler("onResourceStart", resourceRoot, 
   function()
          handler = mysql_connect("127.0.0.1", "root", "9852174563", "mtarace")
   end)
   
function passwordHandler(thePlayer, password, rpassword)
    local account = getPlayerAccount(thePlayer)
	if account then
	   if isGuestAccount(account) then
	      outputChatBox("Error: You must be logged in to change password!", thePlayer, 255, 0, 0)
	   end
	   if password == rpassword then
	      if string.len(password) >=5 then
		     setAccountPassword(account, password)
			 mysql_query(handler, "UPDATE accounts SET password='"..mysql_escape_string(password).."' WHERE username='"..mysql_escape_string(account).."'")
			 triggerClientEvent(thePlayer, "hidePasswordWindow", root)
		  else
		     outputChatBox("Error: You new password must be at least 5 character long!", thePlayer, 255, 0, 0)
		  end
	   else
	      outputChatBox("Error: Your passwords aren't the same!", thePlayer, 255, 0, 0)
	   end
	end
end

function loginHandler(thePlayer, username, password)
    local account = getAccount(username, password)
    local pname = mysql_escape_string(handler, username)
    local ppw = mysql_escape_string(handler, password)
    local query = "SELECT * FROM accounts WHERE username='"..pname.."' and password='"..ppw.."'"
    local result = mysql_query(handler, query)
	local query2 = "SELECT * FROM ban;"
	local result2 = mysql_query(handler, query2)
	if result2 and mysql_num_rows(result2) >0 then
	   row2 = mysql_fetch_assoc(result2)
	   if result and mysql_num_rows(result) >0 then
	      row = mysql_fetch_assoc(result)
          if account ~= false and result and mysql_num_rows(result) > 0 then
	         if (logIn(thePlayer, account, password) == true) then
		         triggerClientEvent(thePlayer, "hideLoginWindow", root)
		         outputChatBox("INFO: Welcome ".. getPlayerName(thePlayer).." you successfully logged in!", thePlayer, 0, 255, 0)
				 setElementData(thePlayer, "account:username", username)
				 setElementData(thePlayer, "account:password", password)
		     else
		        outputChatBox("Error: someone else is logged in", thePlayer, 255, 0, 0)
	         end
	      else
	        outputChatBox("Error: Username or password are incorrect!", thePlayer, 255, 0, 0)
         end
	   end
	end
end

function registerHandler(thePlayer, username, password)
    local account = getAccount(username, password)
	local query = "SELECT * FROM accounts WHERE username='"..username.."'"
	local result = mysql_query(handler, query)
	if account ~= false and result and mysql_num_rows(result) > 0 then
	   outputChatBox("Error: Username already exist!", thePlayer, 255, 0, 0)
	else
	   account = addAccount(username, password)
	   outputChatBox("INFO: you successfully register!", thePlayer, 0, 255, 0)
	   local name = mysql_escape_string(handler, username)
	   local pw = mysql_escape_string(handler, password)
	   local time = getRealTime()
	   local years = time.year
	   local months = time.month
	   local monthdays = time.monthday
	   local hours = time.hour
	   local minutes = time.minute
	   local seconds = time.second
	   local years2 = years+1900
	   local months2 = months+1
	   local alltogether = years2.."-"..months2.."-"..monthdays.." "..hours..":"..minutes..":"..seconds
	   local query = "INSERT INTO accounts SET username='"..name.."',password='"..pw.."', ip='"..getPlayerIP(thePlayer).."', serial='"..getPlayerSerial(thePlayer).."', registerDate='"..alltogether.."'"
	   local result = mysql_query(handler, query)
	end
	if not account and result and mysql_num_rows(result) > 0 then
	   addAccount(username, password)
	   outputChatBox("INFO: you successfully register!", thePlayer, 0, 255, 0)
	end
end


addEvent("submitChangepw", true)
addEvent("submitLogin", true)
addEvent("submitRegister", true)
addEventHandler("submitChangepw", root, passwordHandler)
addEventHandler("submitLogin", root, loginHandler)
addEventHandler("submitRegister", root, registerHandler)

i tried make a remember  but can't make it work all i do is that and get warning on guiSetText at argument 2 is boolen can you help me that i want to do is when a player login the username and  password save and if checkbox is true put the username and password take from there

Edited by Dimos7
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...