Anti SPAM new ideas-for Z-BLOG verification code!

Source: Internet
Author: User

Recently some of our Z-BLOGGER are trying to do what plug-in to stop SPAM, of course, the solution is not no, is to get a super server, but unfortunately can not afford to do. That ...... We have to think about it from the perspective of SPAMMER.
Some people may know that the basic principle of SPAM is [search for a target]-Go to a website-scan a verification code-OCR-[fill in a form]-POST. Each step can be prevented. What is more realistic is to prevent SPAM software from successfully performing OCR verification code. Z-BLOG comes with the verification code is a little weak, interference points is equal to no, feel can easily analyze the number in the verification code. The solution is to change the verification code program.
This verification code program (which I used now) was dug out from the moonlight message book and slightly modified to adapt to Z-BLOG. I personally think it is a little difficult to compile the software OCR verification code. It should be able to exchange for a moment of peace. Of course, this is only a matter of expediency. If it is widely used, there will inevitably be experts to crack it. So ...... It is best to get a server from the official website. Sometimes, I think commercialization or proper investment introduction are good ~
The test results are still in progress, starting from 3 to 28. So far (07-03-30), a total of 1 SPAM (including intercepted .), The content is different from other SPAM. It should not be the work of the spam seo website (two links are boldly added ), in addition, it is not submitted to google, which is searched by a general search engine, to detect webpage malware? ", It is in my message book. Based on the REFERER results, it should be obtained from the homepage (or excluded from other places without executing the script or submitting the refer information), suspected to be a manual SPAM (UPDATE: haphic also receives the same. Is it artificial? He used the original verification code ......), You still need to observe the effect of changing the verification code ......

C_validcode.asp codeCopy codeThe Code is as follows: <% @ CODEPAGE = 65001%>
<% Option Explicit %>
<%
'On Error Resume Next
%>
<! -- # Include file = "../c_option.asp" -->
<! -- # Include file = "../function/c_function.asp" -->
<%

Response. buffer = true

Call Com_CreatValidCode ("CheckCode ")

Rem generates Verification Code Image
Sub Com_CreatValidCode (pSN)
Const codeLenMin = 5' range of digits of the Verification Code
Const codeLenMax = 5' range of digits of the Verification Code
Const cOdds = 2' probability of occurrence of a noise
Const dbtTimes = 1' interference count
Const posX = 3' random range X
Const posY = 2' random position range Y
ImgWidth = 60' image width (to be a multiple of 4)
ImgHeight = 20' Image Height

Const cAmount = 10' font count
Const cCode = "0123456789" 'Character Library
Const UnitWidth = 16' (to be a multiple of 4)
Const UnitHeight = 15' text height
Const DotsLimit = 10' maximum number of valid points to be deleted each time (to avoid human recognition failures)
Const tryCount = 5' prevent attempts to delete valid points from exceeding the upper limit

'-----------

Randomize
Dim I, ii, iii, flag, ActUnitWidth, ImgYuWidth, codeLen, ImgWidth, ImgHeight
CodeLen = codeLenMin + cint (Rnd * (codeLenMax-codeLenMin ))
If ImgWidth Mod 4 <> 0 Or ImgWidth <codeLen * UnitWidth Then ImgWidth = codeLen * UnitWidth
If ImgHeight <UnitHeight Then ImgHeight = UnitHeight

'Prohibit caching
Response. Expires =-9999
Response. AddHeader "Pragma", "no-cache"
Response. AddHeader "cache-ctrol", "no-cache"
Response. ContentType = "Image/BMP"

'Color data (character, background)
Dim vColorData (1)
VColorData (0) = ChrB (0) & ChrB (0) & ChrB (0) 'Blue 0, green 0, red 0 (black) foreground color
VColorData (1) = ChrB (255) & ChrB (255) & ChrB (255) 'Blue 250, green 236, red 211 (light blue) background color

'Character data (you can modify it yourself. If you modify the size, remember to change the previous settings)
Dim vNumberData (9)
VNumberData (0) = "111111111111111111110000000011111110000000000111111001111110011111100111111001111110011111100111111001111110011111100111111001111110011111100111111001111110011111100111111001111110011111100111111000000000011111110000000011111111111111111111"
VNumberData (1) = "111111111111111111111100011111111111000001111111111000000111111111001100011111111111110001111111111111000111111111111100011111111111110001111111111111000111111111111100011111111111110001111111111000000000111111100000000011111111111111111111"
VNumberData (2) = "111111111111111111111100000111111111100000001111111100011100111111100011110011111111111110011111111111110011111111111110011111111111110011111111111110011111111111110011110011111110011111001111111000000000111111100000000011111111111111111111"
VNumberData (3) = "111111111111111111111000000111111111000000001111111001111110011111100111110011111111111110011111111111100011111111111110001111111111111110011111111111111100111111100111111001111110011111100111111100000000111111111000000111111111111111111111"
VNumberData (4) = "111111111111111111111111001111111111101100111111111100110011111111110011001111111110011100111111110011110011111110000000000000111000000000000011111111110011111111111111001111111111111100111111111111110011111111111111001111111111111111111111"
VNumberData (5) = "111111111111111111100000000001111100000000000111110011111111111111001111111111111100111111111111110011000000111111000001111001111111111111100111111111111110011111111111111001111100111111100111110011111110011111100000000011111111111111111111"
VNumberData (6) = "111111111111111111111100000111111111100000001111111100111110011111100111111111111110011111111111111001000001111111100000000011111110001111100111111001111110011111100111111001111110011111100111111100000000111111111000000111111111111111111111"
VNumberData (7) = "111111111111111111100000000001111110000000000111111001111110011111100111111001111111111111001111111111111100111111111111100111111111111100111111111111110011111111111111001111111111111100111111111111110011111111111111001111111111111111111111"
VNumberData (8) = "111111111111111111111000000111111111000000001111111001111110011111100111111001111110011111100111111100000000111111110000000011111111001111001111111001111110011111100111111001111110011111100111111100000000111111111000000111111111111111111111"
VNumberData (9) = "111111111111111111111000000111111111000000001111111001111110011111100111111001111110011111100111111100000000011111110000001001111111111111100111111111111110011111111111111001111110011111001111111100000000111111111000000111111111111111111111"

'Randomly generated characters
Dim vCode (), vCodes
ReDim vCode (codeLen-1)
VCodes = GetVerifyNumber
For I = 0 To 4
VCode (I) = cint (mid (vCodes, I + 1, 1 ))
VCode (I) = pcd_doubter (vNumberData (vCode (I), UnitWidth, UnitHeight, DotsLimit, tryCount, dbtTimes)
Next

'Randomly generated characters
'Dim vCodes
'Redim vCode (codeLen-1)
'For I = 0 To codeLen-1
'Vcode (I) = Int (Rnd * cAmount)
'Vcodes = vCodes & Mid (cCode, vCode (I) + 1, 1)
'Vcode (I) = pcd_doubter (vNumberData (vCode (I), UnitWidth, UnitHeight, DotsLimit, tryCount, dbtTimes)
'Next

'Session (pSN) = vCodes 'record the Session

'Output image file headers
Response. binaryWrite ChrB (66) & ChrB (77) & Num2ChrB (54 + ImgWidth * ImgHeight * 3, 4) & ChrB (0) & ChrB (0) & ChrB (0) & ChrB (0) & ChrB (54) & ChrB (0) & ChrB (0) & ChrB (0) & ChrB (40) & ChrB (0) & ChrB (0) & ChrB (0) & Num2ChrB (ImgWidth, 4) & Num2ChrB (ImgHeight, 4) & ChrB (1) & ChrB (0)

'Output Image Information Headers
Response. binaryWrite ChrB (24) & ChrB (0) & ChrB (0) & ChrB (0) & ChrB (0) & ChrB (0) & Num2ChrB (ImgWidth * ImgHeight * 3, 4) & ChrB (18) & ChrB (11) & ChrB (0) & ChrB (0) & ChrB (18) & ChrB (11) & ChrB (0) & ChrB (0) & ChrB (0) & ChrB (0) & ChrB (0) & ChrB (0) & ChrB (0) & ChrB (0) & ChrB (0) & ChrB (0)

'Generate interference Line'
ReDim noiseLine (1,-1)
Call makeNoise (noiseLine, ImgWidth, ImgHeight)
Call makeNoise (noiseLine, ImgWidth, ImgHeight)
'If you want to copy several more images, you can
'Call makeNoise (noiseLine, ImgWidth, ImgHeight)

'Random location
ActUnitWidth = Int (ImgWidth/codeLen)
ImgYuWidth = ImgWidth-ActUnitWidth * codeLen
ReDim posAry (1, codeLen-1)
PosAry (0, 0) = Int (Rnd) * (posX + (ActUnitWidth-UnitWidth)/2 ))
PosAry (1, 0) = Int (ImgHeight-UnitHeight)/2 + (1-2 * Rnd) * posY)
For I = 1 To codeLen-2
PosAry (0, I) = Int (1-2 * Rnd) * (posX + (ActUnitWidth-UnitWidth)/2 ))
PosAry (1, I) = Int (ImgHeight-UnitHeight)/2 + (1-2 * Rnd) * posY)
Next
If codeLen> 1 Then
PosAry (0, codeLen-1) = Int (Rnd) * (posX + (ActUnitWidth-UnitWidth)/2 ))
PosAry (1, codeLen-1) = Int (ImgHeight-UnitHeight)/2 + (-Rnd) * posY)
End If

'Output image data
For I = ImgHeight-1 To 0 Step-1 'line
For ii = 0 To codeLen-1
For iii = 0 To ActUnitWidth-1 'word width
Flag = 0
If onNoiseLine (noiseLine, ii * ActUnitWidth + iii, I) then' interference line
Flag = 1
ElseIf getUnitDot (posAry, vCode, ii, iii, I, UnitWidth, UnitHeight) = "0" Then
Flag = 1
ElseIf getUnitDot (posAry, vCode, II-1, iii + ActUnitWidth, I, UnitWidth, UnitHeight) = "0" Then
Flag = 1
ElseIf getUnitDot (posAry, vCode, ii + 1, iii-ActUnitWidth, I, UnitWidth, UnitHeight) = "0" Then
Flag = 1
End If
'Random generation of miscellaneous
If Rnd * 99 + 1 <cOdds Then flag = 1-flag
Response. BinaryWrite vColorData (1-flag)
Next
Next
For ii = 0 To ImgYuWidth-1
Response. BinaryWrite vColorData (1)
Next
Next
End Sub

Rem obtains the point of the unit (considering the displacement)
Function getUnitDot (ByRef posAry, ByRef vCode, I, ByVal x, ByVal y, UnitWidth, UnitHeight)
GetUnitDot = "1"
If I <0 Or I> UBound (vCode) Then Exit Function
X = x-posAry (0, I)
If x <0 Or x> = UnitWidth Then Exit Function
Y = y-posAry (1, I)
If y <0 Or y> = UnitHeight Then Exit Function
GetUnitDot = Mid (vCode (I), y * UnitWidth + x + 1, 1)
End Function

Rem generates interference lines
Sub makeNoise (ByRef nl, imgW, UnitHeight)
Dim I, l, x1, y1, x2, y2, dx, dy, deltaT
X1 = Int (Rnd * imgW)
Y1 = Int (Rnd * UnitHeight)
X2 = Int (Rnd * imgW)
Y2 = Int (Rnd * UnitHeight)
Dx = X2-X1
Dy = Y2-Y1
If Abs (dx)> Abs (dy) Then deltaT = Abs (dx) Else deltaT = Abs (dy)
If deltaT = 0 Then Exit Sub
L = UBound (nl, 2)
ReDim Preserve nl (1, l + deltaT + 1)
L = l + 1
For I = 0 To deltaT
Nl (0, l + I) = x1 + dx * I \ deltaT
Nl (1, l + I) = y1 + dy * I \ deltaT
Next
End Sub

Rem determines whether it is an online point of Interference
Function onNoiseLine (ByRef nl, x, y)
OnNoiseLine = False
Dim I
For I = 0 To UBound (nl, 2)
If x = nl (0, I) And y = nl (1, I) Then
OnNoiseLine = True
Exit
End If
Next
End Function

Rem interferes with the lattice of a single word
Rem Interference Idea: randomly generate two endpoints in the dot matrix range, connect them, and create a horizontal axis with a large displacement. Delete the points on the line first, move the vertices (randomly determined) above or below the vertical axis of the deleted vertex to the deleted vertex, and then fill the blank space with the background color.
Function pcd_doubter (ByVal str, UnitWidth, UnitHeight, DotsLimit, tryCount, dbtTimes)
Randomize
Dim x1, x2, y1, y2, dx, dy, deltaT, I, ii, way, f1, f2
For f1 = 1 To dbtTimes interference count
For f2 = 1 To tryCount 'Avoid the number of attempts To delete a valid vertex that exceeds the upper limit
'Randomly determine two endpoints
X1 = int (Rnd * UnitWidth)
X2 = int (Rnd * UnitWidth)
Y1 = int (Rnd * UnitHeight)
Y2 = int (Rnd * UnitHeight)
Dx = X2-X1
Dy = Y2-Y1
If Abs (dx)> Abs (dy) Then deltaT = Abs (dx) Else deltaT = Abs (dy)
ReDim ary (1, deltaT) 'stores connected points
If deltaT = 0 Then
Ary (0, 0) = x1
Ary (1, 0) = y1
Else
Ii = 0
For I = 0 To deltaT
Ary (0, I) = x1 + dx * I \ deltaT
Ary (1, I) = y1 + dy * I \ deltaT
If pcd_getDot (ary (0, I), ary (1, I), str, UnitWidth) = "0" Then ii = ii + 1
Next
'Count the number of valid points on the link. If the number of valid points does not exceed the upper limit of valid points, the loop jumps out and the interference is executed.
If ii <= DotsLimit Then Exit
End If
Next

'Execution disturbance (dx and dy are used for marking in different directions)
If Abs (dx)> Abs (dy) Then dx = 1 Else dx = 0
If dx = 1 Then
If Int (Rnd * 10)> 4 Then
Dy = 1
Way =-1
Else
Dy = UnitHeight-2
Way = 1
End If
Else
If Int (Rnd * 10)> 4 Then
Dy = 1
Way =-1
Else
Dy = UnitWidth-2
Way = 1
End If
End If
For I = 0 To deltaT
For ii = ary (dx, I) To dy Step way
Call pcd_setDot (ary (0, I) * dx + ii * (1-dx), ary (1, I) * (1-dx) + ii * (dx), str, pcd_getDot (ary (0, I) * dx + (ii + way) * (1-dx), ary (1, I) * (1-dx) + (ii + way) * (dx), str, UnitWidth), UnitWidth)
Next
'Fill Blank
Call pcd_setDot (ary (0, I) * dx + (dy + way) * (1-dx), ary (1, I) * (1-dx) + (dy + way) * (dx), str, "1", UnitWidth)
Next
Next
Pcd_doubter = str
End Function

Rem obtains the characters of a vertex.
Function pcd_getDot (x, y, str, UnitWidth)
Pcd_getDot = Mid (str, x + 1 + y * UnitWidth, 1)
End Function

Rem sets the characters of a vertex
Sub pcd_setDot (x, y, ByRef str, newDot, UnitWidth)
Str = Left (str, x + y * UnitWidth) & newDot & Right (str, Len (str)-x-y * UnitWidth-1)
End Sub

The format required for converting the number into bmp is the length of the Target byte.
Function Num2ChrB (ByVal num, lens)
Dim ret, I
Ret = ""
While (num> 0)
Ret = ret & ChrB (num mod 256)
Num = num/256
WEnd
For I = Lenb (ret) To lens-1
Ret = ret & chrB (0)
Next
Num2ChrB = ret
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.