Forums
This topic is locked
strip characters function
Posted 22 Oct 2002 17:21:55
1
has voted
22 Oct 2002 17:21:55 Dave Clarke posted:
hi allI've found this little script which may be of help against sql injection attacks, it strips the characters in the array from a string, could this be edited to strip characters from a form field?
If so how? and then how would i use it?
<%
function killChars(strWords)
dim badChars dim newChars
badChars = array("select", "drop", ";", "--", "insert", "delete", "xp_"

for i = 0 to uBound(badChars) newChars = replace(newChars, badChars(i), ""

killChars = newChars
end function
%>
thanks
Dave
ASP|VBScript|IIS5.1|WinXPPro & WinXPHome
Replies
Replied 26 Oct 2002 08:17:04
26 Oct 2002 08:17:04 Dave Clarke replied:
hello??<img src=../images/dmxzone/forum/icon_smile_big.gif border=0 align=middle>
ASP|VBScript|IIS5.1|WinXPPro & WinXPHome
ASP|VBScript|IIS5.1|WinXPPro & WinXPHome
Replied 26 Oct 2002 23:32:00
26 Oct 2002 23:32:00 Dave Thomas replied:
Wheres the best place to use this function Dave?
Regards,
Dave
UD4 | Flash 5 | SQL | Access | ASP/VBScript | XP-Pro
Regards,
Dave
UD4 | Flash 5 | SQL | Access | ASP/VBScript | XP-Pro
Replied 27 Oct 2002 07:08:58
27 Oct 2002 07:08:58 Dave Clarke replied:
Dunno mate, that's what I'm trying to find out <img src=../images/dmxzone/forum/icon_smile_wink.gif border=0 align=middle>
ASP|VBScript|IIS5.1|WinXPPro & WinXPHome
ASP|VBScript|IIS5.1|WinXPPro & WinXPHome
Replied 27 Oct 2002 15:02:29
27 Oct 2002 15:02:29 Owen Eastwick replied:
Don't use it as a function, instead use as follows:
<%
varString = Request("textFieldName"
' The text entered in the textbox
badChars = array("select", "drop", ";", "--", "insert", "delete", "xp_"
' The bad words we want to get rid of
' Loop throgh the list of bad words and replace them with nothing.
for i = 0 to uBound(badChars) varNewString = replace(varString, badChars(i), ""
next
' Now replace Single quotes with 2 single quotes
varNewString = Replace(varNewString, "'", "''"
%>
Now set up your recordset with a runtime value of varNewString, make sure that the code above appears before the Recordset code.
Regards
Owen.
Multiple Parameter UD4 / Access 2000 Database Search Tutorial:
www.tdsf.co.uk/tdsfdemo
<%
varString = Request("textFieldName"

badChars = array("select", "drop", ";", "--", "insert", "delete", "xp_"

' Loop throgh the list of bad words and replace them with nothing.
for i = 0 to uBound(badChars) varNewString = replace(varString, badChars(i), ""

next
' Now replace Single quotes with 2 single quotes
varNewString = Replace(varNewString, "'", "''"

%>
Now set up your recordset with a runtime value of varNewString, make sure that the code above appears before the Recordset code.
Regards
Owen.
Multiple Parameter UD4 / Access 2000 Database Search Tutorial:
www.tdsf.co.uk/tdsfdemo
Replied 27 Oct 2002 21:54:47
27 Oct 2002 21:54:47 Dave Clarke replied:
Thank you Owen, clear and concise, I'll try it out later, thanks again
Dave
ASP|VBScript|IIS5.1|WinXPPro & WinXPHome
Dave
ASP|VBScript|IIS5.1|WinXPPro & WinXPHome