Feche1320 Posted October 8, 2014 Share Posted October 8, 2014 Hello all, I have a little but big problem.. since I use in-built server SQL lite I have to check that accounts names and passwords aren't with any 'illegal' character since it could cause big problems aka SQL injection, so I made this little script local invalid_Characters = {"$", ",", "'", "\\", "?", "%%", "~", "#", "&", "@", "-", "/", "`", "^", "{", "}", "+", "*", "%(", "%)", "!"} function checkInvalidCharacters(str) local state = false for i, tmp in ipairs(invalid_Characters) do outputChatBox("Checking " ..tmp) if str:find(tmp) then outputChatBox(tmp.. " found on str " ..str) state = true break end end return state end The big problem is that it returns this I tried str:find(tmp, 1, true) but no success.. looks like for loops can't handle invalid_Characters table? thanks Link to comment
MTA Team 0xCiBeR Posted October 8, 2014 MTA Team Share Posted October 8, 2014 (edited) local invalid_Characters = {"$", ",", "'", "\\", "?", "%%", "~", "#", "&", "@", "-", "/", "`", "^", "{", "}", "+", "*", "%(", "%)", "!"} function checkInvalidCharacters(str) local state = false for i, tmp in ipairs(invalid_Characters) do outputChatBox("Checking " ..tmp) if string.find(str,tmp,1,true) then outputChatBox(tmp.. " found on str " ..str) state = true break end end return state end checkInvalidCharacters("helloworld") Edit: I made a change in your script, since it was not correctly set. Please do try it out! Result: Checking $ Checking , Checking ' Checking \ Checking ? Checking %% Checking ~ Checking # Checking & Checking @ Checking - Checking / Checking ` Checking ^ Checking { Checking } Checking + Checking * Checking %( Checking %) Checking ! Edited October 8, 2014 by Guest Link to comment
Feche1320 Posted October 8, 2014 Author Share Posted October 8, 2014 local invalid_Characters = {"$", ",", "'", "\\", "?", "%%", "~", "#", "&", "@", "-", "/", "`", "^", "{", "}", "+", "*", "%(", "%)", "!"} function checkInvalidCharacters(str) local state = false for i, tmp in ipairs(invalid_Characters) do outputChatBox("Checking " ..tmp) if string.find(str,tmp,1,true) then outputChatBox(tmp.. " found on str " ..str) state = true break end end return state end checkInvalidCharacters("helloworld") Result: Checking $ Checking , Checking ' Checking \ Checking ? Checking %% Checking ~ Checking # Checking & Checking @ Checking - Checking / Checking ` Checking ^ Checking { Checking } Checking + Checking * Checking %( Checking %) Checking ! Hmm it is working for you.. what happends if you try checkInvalidCharacters("helloworld$%&") ? Link to comment
MTA Team 0xCiBeR Posted October 8, 2014 MTA Team Share Posted October 8, 2014 Checking $ $ found on str helloworld$%& 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