[Original] ASP Security Detection and filtering function SafeCheck

Source: Internet
Author: User

'--------------------------------------------------------------------------
'Role: Security string Detection Function
'Name: safecheck
'Parameter: checkstring, checktype, checklength
'Note:
'Checkstring string to be detected: any character.
'Checktype detection Type 0 normal short character 1 digit 2 date 3 money 4 encoding HTML5 decoding html6 login string 7 attack prevention detection
'Checklength detection type length: int type, decimal point when it is money
'Return value: If detection is successful, the correct string is returned,
'The error code system_error | error_code is returned if it fails.
'Script writen by: snowdu (Du Xue. Net)
'Web: http://www.snsites.com/
'--------------------------------------------------------------------------
Function safecheck (checkstring, checktype, checklength)
On Error resume next
Errorroot = "system_error |"
If checkstring = "" then
Safecheck = errorroot & "00001"
Exit Function
End if

CheckString = Replace (CheckString, "'", "& #39 ")
Select case CheckType
Case 0
CheckString = trim (CheckString)
SafeCheck = Left (CheckString, CheckLength)
Case 1
If not isnumberic (CheckString) then
SafeCheck = ErrorRoot & "00002"
Exit function
Else
SafeCheck = Left (CheckString, CheckLength)
End if
Case 2
TempVar = IsDate (CheckString)
If Not TempVar then
SafeCheck = ErrorRoot & "00003"
Exit function
Else
Select case CheckLength
Case 0
SafeCheck = FormatDateTime (CheckString, vb1_date)
Case 1
SafeCheck = FormatDateTime (CheckString, vbLongDate)
Case 2
SafeCheck = CheckString
End select
End if
Case 3
TempVar = FormatCurrency (CheckString, 0)
If Err then
SafeCheck = ErrorRoot & "00004"
Exit function
Else
SafeCheck = FormatCurrency (CheckString, CheckLength)
End if
Case 4
STemp = CheckString
If IsNull (sTemp) = True Then
SafeCheck = ErrorRoot & "00005"
Exit Function
End If
STemp = Replace (sTemp, "&", "& amp ;")
STemp = Replace (sTemp, "<", "& lt ;")
STemp = Replace (sTemp, ">", "& gt ;")
STemp = Replace (sTemp, Chr (34), "& quot ;")
STemp = Replace (sTemp, Chr (10), "<br> ")
SafeCheck = Left (sTemp, CheckLength)
Case 5
STemp = CheckString
If IsNull (sTemp) = True Then
SafeCheck = ErrorRoot & "00006"
Exit Function
End If
STemp = Replace (sTemp, "& amp ;","&")
STemp = Replace (sTemp, "& lt;", "<")
STemp = Replace (sTemp, "& gt;", "> ")
STemp = Replace (sTemp, "& quot;", Chr (34 ))
STemp = Replace (sTemp, "<br>", Chr (10 ))
SafeCheck = Left (sTemp, CheckLength)
Case 6
S_BadStr = "'& <>? % ,;:()'~! @ # $ ^ * {} [] | +-= "& Chr (34) & Chr (9) & Chr (32)
N = Len (s_BadStr)
IsSafeStr = True
For I = 1 To n
If Instr (CheckString, Mid (s_BadStr, I, 1)> 0 Then
IsSafeStr = False
End If
Next
If IsSafeStr then
SafeCheck = left (CheckString, CheckLength)
Else
SafeCheck = ErrorRoot & "00007"
Exit Function
End if
Case 7
S_Filter = "net user | xp_mongoshell |/add | select | count | asc | char | mid | '|" "|"
S_Filter = S_Filter & "insert | delete | drop | truncate | from | % | declare | -"
S_Filters = split (S_Filter, "| ")
IsFound = false
For I = 0 to ubound (S_Filters)-1
If Instr (lcase (CheckString), lcase (S_Filters (I) <> 0 then
IsFound = true
Exit
End if
Next
If isFound then
SafeCheck = ErrorRoot & "00008"
Exit Function
Else
SafeCheck = left (CheckString, CheckLength)
End if
End select
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.