Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parse SQL forbidden characters

Status
Not open for further replies.

pgferro

Programmer
Aug 21, 2001
111
BS
Hi Guys,

Does anybody have a function ready to parse all forbidden SQL characters for an insert/update statement ?

(like single quote, %, &, ect..)

I know, I'm lazy !

:)
 
You can't simply remove all those characters from a prebuilt statement, you have to parse through each string as you build it into an insert/update statement.

As far as that goes, you only need to worry about single quotes, and the way to fix them is something like:

Function DoubleUpSingleQuotes(strInput)
'```<--- replace prime (single quote) with reverse prime
DoubleUpSingleQuotes = Replace(strInput, "'", "''")
End Function
 
3 standard ones I use to limit SQL Injection are

Code:
function stripQuotes(strWords)
'strip out single quotes for SQL injection attempts 
stripQuotes = replace(strWords, "'", "''")
stripQuotes =  StripChars(stripQuotes)
end function 
'***********************************

function StripChars(strIn) 
dim Disallowed 
dim strOut 
dim i

Disallowed = array("select", "drop", ";", "--", "insert","delete", "xp_") 
strOut = strIn 

for i = 0 to uBound(Disallowed) 
strOut = replace(strOut, Disallowed(i), "") 
next 
StripChars = strOut 
end function 
'*************************************

function CheckBad(strIn, Pattern)
dim objRE
set objRE = New RegExp 
objRE.pattern = Pattern
CheckBad = objRE.Test(strIn)
end function
'*************************************

the call to CheckBad is usually

CheckBad(username,"[=;'" & chr(34) &"]")

to test for "=", ";" "'" (single quote) and """ (double quote)



Chris.

Indifference will be the downfall of mankind, but who cares?
A website that proves the cobblers kids adage.
Nightclub counting systems

So long, and thanks for all the fish.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top