Y
Yadda
'Clean troublesome characters used in SQL INJECTION attacks.
Function cleanUserInput(strUserInput As String) As String
Dim cleanChar As String
Dim singleQuote As String
Dim semiColon As String
Dim doubleDash As String
Dim commentStart As String
Dim commentEnd As String
cleanChar = Chr(32) 'space character which the SQL parser ignores
singleQuote = Chr(39)
semiColon = Chr(59)
doubleDash = Chr(45) & Chr(45)
commentStart = Chr(47) & Chr(42)
commentEnd = Chr(42) & Chr(47)
debug.print singleQuote, semicolon, doubleDash, commentStart,
commentEnd
' replace single quote with two single quotes; also properly
formats legit possession and contractions
strUserInput = Replace(strUserInput, singleQuote, singleQuote &
singleQuote)
' remove semicolon command delimiter
strUserInput = Replace(strUserInput, semiColon, cleanChar)
' remove double dash comment
strUserInput = Replace(strUserInput, doubleDash, cleanChar)
' remove slash begin comment
strUserInput = Replace(strUserInput, commentStart, cleanChar)
' remove slash end comment
strUserInput = Replace(strUserInput, commentEnd, cleanChar)
'remove xp_ external commands
strUserInput = Replace(strUserInput, "xp_", cleanChar)
cleanUserInput = Trim(strUserInput)
Debug.Print cleanUserInput
End Function
Function cleanUserInput(strUserInput As String) As String
Dim cleanChar As String
Dim singleQuote As String
Dim semiColon As String
Dim doubleDash As String
Dim commentStart As String
Dim commentEnd As String
cleanChar = Chr(32) 'space character which the SQL parser ignores
singleQuote = Chr(39)
semiColon = Chr(59)
doubleDash = Chr(45) & Chr(45)
commentStart = Chr(47) & Chr(42)
commentEnd = Chr(42) & Chr(47)
debug.print singleQuote, semicolon, doubleDash, commentStart,
commentEnd
' replace single quote with two single quotes; also properly
formats legit possession and contractions
strUserInput = Replace(strUserInput, singleQuote, singleQuote &
singleQuote)
' remove semicolon command delimiter
strUserInput = Replace(strUserInput, semiColon, cleanChar)
' remove double dash comment
strUserInput = Replace(strUserInput, doubleDash, cleanChar)
' remove slash begin comment
strUserInput = Replace(strUserInput, commentStart, cleanChar)
' remove slash end comment
strUserInput = Replace(strUserInput, commentEnd, cleanChar)
'remove xp_ external commands
strUserInput = Replace(strUserInput, "xp_", cleanChar)
cleanUserInput = Trim(strUserInput)
Debug.Print cleanUserInput
End Function