一聚教程网:一个值得你收藏的教程网站

热门教程

sql 安全过滤函数 asp sql 防注入函数

时间:2022-06-30 09:13:56 编辑:袖梨 来源:一聚教程网

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(13),"
")
  tempStr = Replace(tempStr,"""",""")
  tempStr = Replace(tempStr,"<","<")
  tempStr = Replace(tempStr,">",">")
  tempStr = Replace(tempStr,"*","*")
  tempStr = Replace(tempStr,"%","%")
  tempStr = Replace(tempStr,"'","'")
  tempStr = Replace(tempStr,"script","Script")
  tempStr = Replace(tempStr,"object","Object")
  tempStr = Replace(tempStr,"applet","Applet")
  tempStr = Replace(tempStr,"select","select")
  tempStr = Replace(tempStr,"execute","execute")
  tempStr = Replace(tempStr,"exec","exec")
  tempStr = Replace(tempStr,"join","join")
  tempStr = Replace(tempStr,"union","union")
  tempStr = Replace(tempStr,"where","where")
  tempStr = Replace(tempStr,"insert","insert")
  tempStr = Replace(tempStr,"delete","delete")
  tempStr = Replace(tempStr,"update","update")
  tempStr = Replace(tempStr,"like","like")
  tempStr = Replace(tempStr,"drop","drop")
  tempStr = Replace(tempStr,"create","create")
  tempStr = Replace(tempStr,"rename","rename")
  tempStr = Replace(tempStr,"count","count")
  tempStr = Replace(tempStr,"chr","chr")
  tempStr = Replace(tempStr,"mid","mid")
  tempStr = Replace(tempStr,"truncate","truncate")
  tempStr = Replace(tempStr,"nchar","nchar")
  tempStr = Replace(tempStr,"char","char")
  tempStr = Replace(tempStr,"alter","alter")
  tempStr = Replace(tempStr,"cast","cast")
  tempStr = Replace(tempStr,"exists","exists")
  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
   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 UBound(errSqlSplit)
   If InStr(sqlStr,errSqlSplit(i)) <> 0 Then j = j + 1
  Next
  If j = 0 Then
   SelectSql = True
  Else
   SelectSql = False
  End If
 End Function

热门栏目