Jump to content

Problem checking invalid characters..


Feche1320

Recommended Posts

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

hYIPjD8.png

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
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 by Guest
Link to comment
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

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