matucha123 Posted February 12, 2012 Share Posted February 12, 2012 Hello. My login script isnt case sensitive. Server side: function loginHandler(player, username, password) result = mysql_query(mysqldb, "Select * From players Where username='"..username.. "' AND pass='"..password.. "'") if(result ~= nil) then if(mysql_num_rows(result) > 0) then spawnPlayer(player, spawnX, spawnY, spawnZ) fadeCamera(player, true) setCameraTarget(player, player) outputChatBox("Welcome to My Server.", player) mysql_free_result(result) else outputChatBox("Invalid username and password. Please try again.",player) triggerClientEvent ("falseLogin", getRootElement()) mysql_free_result(result) return end end end addEvent("submitLogin", true) addEventHandler("submitLogin", getRootElement(), loginHandler) Client side: function clientSubmitLogin(button,state) if button == "left" and state == "up" then local username = guiGetText(edtUser) local password = guiGetText(edtPass) if username and password then triggerServerEvent("submitLogin", getRootElement(), getLocalPlayer(), username, password) guiSetInputEnabled(false) guiSetVisible(wdwLogin, false) showCursor(false) else outputChatBox("Please enter a username and password.") end end end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function () createLoginRegisterGUI() outputChatBox("Welcome to My MTA:SA Server.") if (wdwLogin ~= nil) then guiSetVisible(wdwLogin, true) else outputChatBox("An unexpected error has occurred and the log in GUI has not been created.") end showCursor(true) guiSetInputEnabled(true) end ) addEvent( "falseLogin", true) addEventHandler("falseLogin", getResourceRootElement(getThisResource()), function() guiSetInputEnabled(true) guiSetVisible(wdwLogin, true) showCursor(true) end ) Thanks for help Link to comment
Kenix Posted February 12, 2012 Share Posted February 12, 2012 Try Server addEvent( "submitLogin", true ) function loginHandler( username, password ) local result = mysql_query( mysqldb, "SELECT * FROM players WHERE username = '"..username.. "' AND pass = '"..password.. "'" ) if not result then outputDebugString( "mysql_query failed: (" .. tostring( mysql_errno( mysqldb ) ).. ") " ..tostring( mysql_error( mysqldb ) ) ) else if mysql_num_rows( result ) > 0 then spawnPlayer( source, spawnX, spawnY, spawnZ ) fadeCamera( source, true) setCameraTarget( source, source ) outputChatBox( "Welcome to My Server.", source ) else outputChatBox( "Invalid username and password. Please try again.",source ) triggerClientEvent ( "falseLogin", root ) end end mysql_free_result( result ) end addEventHandler( "submitLogin", root, loginHandler ) Client addEvent( "falseLogin", true) function clientSubmitLogin( button,state ) if button == "left" and state == "up" then local username = guiGetText( edtUser ) local password = guiGetText( edtPass ) if username and password then triggerServerEvent( "submitLogin", localPlayer, username, password ) guiSetInputEnabled( false) guiSetVisible( wdwLogin, false) showCursor( false ) else outputChatBox("Please enter a username and password.") end end end addEventHandler( "onClientResourceStart", resourceRoot, function ( ) createLoginRegisterGUI( ) outputChatBox( "Welcome to My MTA:SA Server." ) if wdwLogin then guiSetVisible( wdwLogin, true ) else outputChatBox( "An unexpected error has occurred and the log in GUI has not been created." ) end showCursor( true ) guiSetInputEnabled( true ) end ) addEventHandler( "falseLogin", root, function( ) guiSetInputEnabled( true ) guiSetVisible( wdwLogin, true ) showCursor( true ) end ) Your variables spawnX, spawnY, spawnZ define? Link to comment
matucha123 Posted February 12, 2012 Author Share Posted February 12, 2012 local spawnX, spawnY, spawnZ = 1959.55, -1714.46, 20 tried your script. Same. Maybe MySQL database isn't case sensitive? Link to comment
Kenix Posted February 12, 2012 Share Posted February 12, 2012 local spawnX, spawnY, spawnZ = 1959.55, -1714.46, 20 tried your script. Same. Maybe MySQL database isn't case sensitive? You can show how you connect to db.? Better show full code. Link to comment
matucha123 Posted February 12, 2012 Author Share Posted February 12, 2012 Server: local spawnX, spawnY, spawnZ = 1959.55, -1714.46, 20 addEvent( "submitLogin", true ) function loginHandler( username, password ) local result = mysql_query( mysqldb, "SELECT * FROM players WHERE username = '"..username.. "' AND pass = '"..password.. "'" ) if not result then outputDebugString( "mysql_query failed: (" .. tostring( mysql_errno( mysqldb ) ).. ") " ..tostring( mysql_error( mysqldb ) ) ) else if mysql_num_rows( result ) > 0 then spawnPlayer( source, spawnX, spawnY, spawnZ ) fadeCamera( source, true) setCameraTarget( source, source ) outputChatBox( "Welcome to My Server.", source ) else outputChatBox( "Invalid username and password. Please try again.",source ) triggerClientEvent ( "falseLogin", root ) end end mysql_free_result( result ) end addEventHandler( "submitLogin", root, loginHandler ) function registerHandler(player, user, pass, repass) result = mysql_query(mysqldb, "Select * From players Where username='"..user.."'") if(result ~= nil) then if(mysql_num_rows(result) > 0) then outputChatBox("Username which you selected already exists!",source, 255, 0, 0) mysql_free_result(result) else mysql_free_result(result) result = mysql_query(mysqldb, "Insert into players (username, pass) values ('"..user.."', '"..pass.."')") outputChatBox("Succes register", source) return end end end addEvent("submitRegister", true) addEventHandler("submitRegister", getRootElement(), registerHandler) addEventHandler( "onPlayerWasted", getRootElement( ), function() setTimer( spawnPlayer, 2000, 1, source, spawnX, spawnY, spawnZ) end ) function connectMySQLdb() mysqldb = mysql_connect("localhost", "", "", "mtadb") end addEventHandler ( "onResourceStart", getRootElement(), connectMySQLdb ) Client: function createLoginRegisterGUI() local X = 0.375 local Y = 0.375 local Width = 0.35 local Height = 0.35 myFont = guiCreateFont( "password.ttf", 15 ) wdwLogin = guiCreateWindow(X, Y, Width, Height, "Login/Register window", true) local tabPanel = guiCreateTabPanel ( 0, 0.1, 1, 1, true, wdwLogin) local tabLogin = guiCreateTab( "Login", tabPanel ) local tabRegister = guiCreateTab( "Register", tabPanel ) X = 0.0825 Y = 0.2 Width = 0.25 Height = 0.25 guiCreateLabel(X, Y, Width, Height, "Username", true, tabLogin) Y = 0.5 guiCreateLabel(X, Y, Width, Height, "Password", true, tabLogin) X = 0.315 Y = 0.2 Width = 0.6 Height = 0.15 edtUser = guiCreateEdit(X, Y, Width, Height, "", true, tabLogin) Y = 0.5 edtPass = guiCreateEdit(X, Y, Width, Height, "", true, tabLogin) guiSetFont(edtPass, myFont ) guiEditSetMaxLength(edtUser, 50) guiEditSetMaxLength(edtPass, 50) X = 0.05 Y = 0.7 Width = 0.9 Height = 0.15 btnLogin = guiCreateButton(X, Y, Width, Height, "Log In", true, tabLogin) --========================Regsiter=============================================== X = 0.0825 Y = 0.21 Width = 0.2 Height = 0.2 guiCreateLabel(X, Y, Width, Height, "Username", true, tabRegister) Y = 0.41 guiCreateLabel(X, Y, Width, Height, "Password", true, tabRegister) Y = 0.61 guiCreateLabel(X, Y, Width, Height, "Repeat password", true, tabRegister) X = 0.315 Y = 0.2 Width = 0.6 Height = 0.1 edtReUser = guiCreateEdit(X, Y, Width, Height, "", true, tabRegister) Y = 0.4 edtRegPass = guiCreateEdit(X, Y, Width, Height, "", true, tabRegister) Y = 0.6 edtRePass = guiCreateEdit(X, Y, Width, Height, "", true, tabRegister) myFont = guiCreateFont( "password.ttf", 10 ) guiSetFont( edtRegPass, myFont ) guiSetFont( edtRePass, myFont ) guiEditSetMaxLength(edtReUser, 50) guiEditSetMaxLength(edtRegPass, 50) guiEditSetMaxLength(edtRePass, 50) X = 0.05 Y = 0.8 Width = 0.9 Height = 0.15 btnRegister = guiCreateButton(X, Y, Width, Height, "Register", true, tabRegister) guiSetVisible(wdwLogin, false) addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) addEventHandler("onClientGUIClick", btnRegister, clientSubmitRegister, false) end function clientSubmitRegister(button, state) if button == "left" and state == "up" then local username = guiGetText(edtReUser) local password = guiGetText(edtRegPass) local repass = guiGetText(edtRePass) if username and password then triggerServerEvent("submitRegister", getRootElement(), getLocalPlayer(), username, password, repass) end end end addEvent( "falseLogin", true) function clientSubmitLogin( button,state ) if button == "left" and state == "up" then local username = guiGetText( edtUser ) local password = guiGetText( edtPass ) if username and password then triggerServerEvent( "submitLogin", localPlayer, username, password ) guiSetInputEnabled( false) guiSetVisible( wdwLogin, false) showCursor( false ) else outputChatBox("Please enter a username and password.") end end end addEventHandler( "onClientResourceStart", resourceRoot, function ( ) createLoginRegisterGUI( ) outputChatBox( "Welcome to My MTA:SA Server." ) if wdwLogin then guiSetVisible( wdwLogin, true ) else outputChatBox( "An unexpected error has occurred and the log in GUI has not been created." ) end showCursor( true ) guiSetInputEnabled( true ) end ) addEventHandler( "falseLogin", root, function( ) guiSetInputEnabled( true ) guiSetVisible( wdwLogin, true ) showCursor( true ) end ) Link to comment
Kenix Posted February 12, 2012 Share Posted February 12, 2012 Server local spawnX, spawnY, spawnZ = 1959.55, -1714.46, 20 local mysqldb addEvent( "submitLogin", true ) addEvent( "submitRegister", true ) function connectToMysql ( ) mysqldb = mysql_connect( "localhost", "", "", "mtadb" ) if mysqldb then outputDebugString( 'CONNECTION SUCCES' ) else outputDebugString( 'CONNECTION NOT SUCCES' ) end end function disconnectToMysql( ) if mysqldb then mysql_close( mysqldb ) end end function loginHandler( username, password ) local result = mysql_query( mysqldb, "SELECT * FROM players WHERE username = '"..username.. "' AND pass = '"..password.. "'" ) if not result then outputDebugString( "EVENT:submitLogin mysql_query failed: (" .. tostring( mysql_errno( mysqldb ) ).. ") " ..tostring( mysql_error( mysqldb ) ) ) else if mysql_num_rows( result ) > 0 then spawnPlayer( source, spawnX, spawnY, spawnZ ) fadeCamera( source, true) setCameraTarget( source, source ) outputChatBox( "Welcome to My Server.", source ) else outputChatBox( "Invalid username and password. Please try again.",source ) triggerClientEvent ( "falseLogin", root ) end mysql_free_result( result ) end end function registerHandler( user, pass, repass ) local result = mysql_query( mysqldb, "SELECT * FROM players WHERE username = '"..user.."'" ) if not result then outputDebugString( "EVENT:submitRegister mysql_query failed: (" .. tostring( mysql_errno( mysqldb ) ).. ") " ..tostring( mysql_error( mysqldb ) ) ) else if mysql_num_rows( result ) > 0 then outputChatBox( "Username which you selected already exists!",source, 255, 0, 0 ) else local Result = mysql_query( mysqldb, "INSERT INTO players (username, pass) VALUES ('"..user.."', '"..pass.."')" ) if Result then outputChatBox( "Succes register", source ) mysql_free_result( Result ) else outputDebugString( "Register not succes: mysql_query failed: (" .. tostring( mysql_errno( mysqldb ) ).. ") " ..tostring( mysql_error( mysqldb ) ) ) end end mysql_free_result( result ) end end addEventHandler( "onPlayerWasted", root, function() setTimer( spawnPlayer, 2000, 1, source, spawnX, spawnY, spawnZ ) end ) --addCommandHandler( "vehicle", createVehicleForPlayer ) addEventHandler ( "onResourceStart", resourceRoot,connectToMysql ) addEventHandler( 'onResourceStop', resourceRoot,disconnectToMysql ) addEventHandler( "submitRegister", root, registerHandler ) addEventHandler( "submitLogin", root, loginHandler ) Client addEvent( "falseLogin", true) function createLoginRegisterGUI( ) local X = 0.375 local Y = 0.375 local Width = 0.35 local Height = 0.35 myFont = guiCreateFont( "password.ttf", 15 ) wdwLogin = guiCreateWindow(X, Y, Width, Height, "Login/Register window", true) local tabPanel = guiCreateTabPanel ( 0, 0.1, 1, 1, true, wdwLogin) local tabLogin = guiCreateTab( "Login", tabPanel ) local tabRegister = guiCreateTab( "Register", tabPanel ) X = 0.0825 Y = 0.2 Width = 0.25 Height = 0.25 guiCreateLabel(X, Y, Width, Height, "Username", true, tabLogin) Y = 0.5 guiCreateLabel(X, Y, Width, Height, "Password", true, tabLogin) X = 0.315 Y = 0.2 Width = 0.6 Height = 0.15 edtUser = guiCreateEdit(X, Y, Width, Height, "", true, tabLogin) Y = 0.5 edtPass = guiCreateEdit(X, Y, Width, Height, "", true, tabLogin) guiSetFont(edtPass, myFont ) guiEditSetMaxLength(edtUser, 50) guiEditSetMaxLength(edtPass, 50) X = 0.05 Y = 0.7 Width = 0.9 Height = 0.15 btnLogin = guiCreateButton(X, Y, Width, Height, "Log In", true, tabLogin) --========================Regsiter=============================================== X = 0.0825 Y = 0.21 Width = 0.2 Height = 0.2 guiCreateLabel(X, Y, Width, Height, "Username", true, tabRegister) Y = 0.41 guiCreateLabel(X, Y, Width, Height, "Password", true, tabRegister) Y = 0.61 guiCreateLabel(X, Y, Width, Height, "Repeat password", true, tabRegister) X = 0.315 Y = 0.2 Width = 0.6 Height = 0.1 edtReUser = guiCreateEdit(X, Y, Width, Height, "", true, tabRegister) Y = 0.4 edtRegPass = guiCreateEdit(X, Y, Width, Height, "", true, tabRegister) Y = 0.6 edtRePass = guiCreateEdit(X, Y, Width, Height, "", true, tabRegister) myFont = guiCreateFont( "password.ttf", 10 ) guiSetFont( edtRegPass, myFont ) guiSetFont( edtRePass, myFont ) guiEditSetMaxLength(edtReUser, 50) guiEditSetMaxLength(edtRegPass, 50) guiEditSetMaxLength(edtRePass, 50) X = 0.05 Y = 0.8 Width = 0.9 Height = 0.15 btnRegister = guiCreateButton(X, Y, Width, Height, "Register", true, tabRegister) guiSetVisible(wdwLogin, false) addEventHandler( "onClientGUIClick", btnLogin, clientSubmitLogin, false ) addEventHandler( "onClientGUIClick", btnRegister, clientSubmitRegister, false ) end function clientSubmitRegister(button, state) if button == "left" and state == "up" then local username = guiGetText(edtReUser) local password = guiGetText(edtRegPass) local repass = guiGetText(edtRePass) if username and password then triggerServerEvent( "submitRegister", localPlayer, username, password, repass ) end end end function clientSubmitLogin( button,state ) if button == "left" and state == "up" then local username = guiGetText( edtUser ) local password = guiGetText( edtPass ) if username and password then triggerServerEvent( "submitLogin", localPlayer, username, password ) guiSetInputEnabled( false) guiSetVisible( wdwLogin, false) showCursor( false ) else outputChatBox("Please enter a username and password.") end end end addEventHandler( "onClientResourceStart", resourceRoot, function ( ) createLoginRegisterGUI( ) outputChatBox( "Welcome to My MTA:SA Server." ) if wdwLogin then guiSetVisible( wdwLogin, true ) else outputChatBox( "An unexpected error has occurred and the log in GUI has not been created." ) end showCursor( true ) guiSetInputEnabled( true ) end ) addEventHandler( "falseLogin", root, function( ) guiSetInputEnabled( true ) guiSetVisible( wdwLogin, true ) showCursor( true ) end ) Try it /debugscript 3. Link to comment
matucha123 Posted February 12, 2012 Author Share Posted February 12, 2012 connection is successful. Link to comment
Kenix Posted February 12, 2012 Share Posted February 12, 2012 connection is successful. So it working? Link to comment
matucha123 Posted February 12, 2012 Author Share Posted February 12, 2012 No... its wont work with random username, but its can connect with right one. Example: In mysql username is james. i can connect with JaMes In mysql password is mta. I can connect with MtA Link to comment
Kenix Posted February 12, 2012 Share Posted February 12, 2012 (edited) No... its wont work with random username, but its can connect with right one. Example:In mysql username is james. i can connect with JaMes In mysql password is mta. I can connect with MtA Ah i not understand your first post Yes, mysql is not case sensitive. Request,tables,... But you can create it. http://dev.mysql.com/doc/refman/5.0/en/ ... ivity.html Edited February 12, 2012 by Guest Link to comment
matucha123 Posted February 12, 2012 Author Share Posted February 12, 2012 how can I make case sensitive? hash password in whirlpool or MD5? Link to comment
Kenix Posted February 12, 2012 Share Posted February 12, 2012 http://dev.mysql.com/doc/refman/5.0/en/ ... ivity.html 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