SQL security filtering function ASP SQL anti-injection function

Source: Internet
Author: User

Public Function safesql (str)
Dim TempStr
TempStr = Trim (LCase (str))
If TempStr = "" or IsNull (TEMPSTR) or IsEmpty (TEMPSTR) Then
Safesql = ""
Exit Function
End If
TempStr = Replace (TEMPSTR,CHR (0), "")
TempStr = Replace (TEMPSTR,CHR (), "<br/>")
TempStr = Replace (TempStr, "" "", "&quot;")
TempStr = Replace (TempStr, "<", "&lt;")
TempStr = Replace (TempStr, ">", "&gt;")
TempStr = Replace (TempStr, "*", "& #042;")
TempStr = Replace (tempstr, "%", "& #037;")
TempStr = Replace (TempStr, "'", "& #039;")
TempStr = Replace (tempstr, "script", "& #083; Cript")
TempStr = Replace (TempStr, "Object", "& #079; Bject")
TempStr = Replace (TempStr, applet, & #065;pp Let)
TempStr = Replace (TempStr, "select", "sel& #101; CT")
TempStr = Replace (TempStr, "Execute", "& #101xecute")
TempStr = Replace (TempStr, "exec", "& #101xec")
TempStr = Replace (TempStr, "join", "jo& #105; n")
TempStr = Replace (TEMPSTR, "union", "un& #105; on")
TempStr = Replace (TempStr, "where", "wh& #101; Re")
TempStr = Replace (TempStr, "Insert", "ins& #101; RT")
TempStr = Replace (tempstr, "delete", "del& #101; TE")
TempStr = Replace (tempstr, "Update", "up& #100; ate")
TempStr = Replace (TempStr, "like", "lik& #101;")
TempStr = Replace (TempStr, "drop", "dro& #112;")
TempStr = Replace (TempStr, "create", "cr& #101; ate")
TempStr = Replace (tempstr, "rename", "ren& #097; Me")
TempStr = Replace (TempStr, "Count", "co& #117; NT")
TempStr = Replace (tempstr, "Chr", "c& #104; R")
TempStr = Replace (TempStr, "mid", "m& #105;d")
TempStr = Replace (TempStr, "truncate", "trunc& #097; TE")
TempStr = Replace (tempstr, "nchar", "nch& #097; R")
TempStr = Replace (tempstr, "char", "ch& #097; R")
TempStr = Replace (TEMPSTR, "Alter", "alt& #101; R")
TempStr = Replace (tempstr, "cast", "ca& #115; t")
TempStr = Replace (TempStr, "exists", "e& #120; ists")
If tempstr = LCase (str) Then
Safesql = str
Else
Safesql = TempStr
End If
End Function

Public Function Selectsql (sqlstr)
  if sqlstr = "" Or IsNull (SQLSTR) Or IsEmpty (sqlstr) Then
&NBSP;&N Bsp; selectsql = True
   exit Function
  end If
  dim errsqlstr, Errsqlsplit,i,j
  sqlstr = LCase (sqlstr)
  errsqlstr = "Insert,update,delete,create,drop , alter,rename "
  errsqlsplit = Split (Errsqlstr,", ")
  j = 0
  for i = 0 to Uboun D (errsqlsplit)
   if InStr (Sqlstr,errsqlsplit (i)) <> 0 Then j = j + 1
  next
&N Bsp; if j = 0 Then
   selectsql = True
  else
   selectsql = Fal Se
  end If
 end Function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.