ASP generated digital addition and summation of BMP picture Verification code _ Application Tips

Source: Internet
Author: User
Tags abs
There are many image verification code forms on the network, those who do not generate the image of the verification code of the anti-cracking defense capability is simply vulnerable; someone directly in the source code to show the specific number, and then ask the visitor to enter a sum after the and, such as 3+5= how much, such a new code of verification, but unfortunately, Does not play a role in protection at all.

Flymorn improve the above new ideas, directly 3+6= how many forms of the use of ASP program to generate BMP picture format, and the number added and stored in the session, to increase the threshold of cracking; there is no graphic image to learn knowledge of the people can not be cracked. The code is as follows:

Copy Code code as follows:

<%
Response.Buffer = True
Response.ExpiresAbsolute = Now ()-1
Response.Expires = 0
Response.CacheControl = "No-cache"

Response.ContentType = "Image/bmp"

Call Com_creatvalidcode ()

Sub Com_creatvalidcode ()

Randomize

Dim I, II, III

Const Camount = 10 ' Number of values

Const ccode = "0123456789" ' Numerical range

Dim Vcolordata (2)

Vcolordata (0) = "" ' Black point to be converted to colored dots, temporarily undefined

Vcolordata (1) = ChrB (255) & ChrB (255) & ChrB (255) ' White dots

Dim Vcode (4), Vcodes ' produces a set of arbitrary numbers

For i = 0 to 3

Vcode (i) = Int (Rnd * camount) ' array equals total * random number

If I=1 then Vcode (i) = "11" ' second digit +

If I=3 then Vcode (i) = "10" ' fourth bit =

Vcodes=vcodes&mid (Ccode,vcode (i) +1,1) ' string equals string plus subsequent value

Next

Session ("Checkcode") =int (Mid (vcodes,1,1)) + Int (mid (vcodes,2,1)) ' Calculates the Add and value and assigns values to the session

Dim Vnumberdata (36)

Vnumberdata (0) =

"1110000111110111101111011110111101111011110111101111011110111101111011110111101111011110111110000111"

Vnumberdata (1) =

"1111011111110001111111110111111111011111111101111111110111111111011111111101111111110111111100000111"

Vnumberdata (2) =

"1110000111110111101111011110111111111011111111011111111011111111011111111011111111011110111100000011"

Vnumberdata (3) =

"1110000111110111101111011110111111110111111100111111111101111111111011110111101111011110111110000111"

Vnumberdata (4) =

"1111101111111110111111110011111110101111110110111111011011111100000011111110111111111011111111000011"

Vnumberdata (5) =

"1100000011110111111111011111111101000111110011101111111110111111111011110111101111011110111110000111"

Vnumberdata (6) =

"1111000111111011101111011111111101111111110100011111001110111101111011110111101111011110111110000111"

Vnumberdata (7) =

"1100000011110111011111011101111111101111111110111111110111111111011111111101111111110111111111011111"

Vnumberdata (8) =

"1110000111110111101111011110111101111011111000011111101101111101111011110111101111011110111110000111"

Vnumberdata (9) =

"1110001111110111011111011110111101111011110111001111100010111111111011111111101111011101111110001111"

' Expression =
Vnumberdata (10) =

"1111111111111111111111111111111000000001111111111111111111111000000001111111111111111111111111111111"
' means +
Vnumberdata (11) =

"1111111111111100111111110011111111001111100000000110000000011111001111111100111111110011111111111111"


Response.BinaryWrite ChrB & ChrB (a) & ChrB (230) & ChrB (4) & ChrB (0) & ChrB (0) & ChrB (0) & ChrB (0) &_

ChrB (0) & ChrB (0) & ChrB (a) & ChrB (0) & ChrB (0) & ChrB (0) & ChrB () & ChrB (0) &_

ChrB (0) & ChrB (0) & ChrB (+) & ChrB (0) & ChrB (0) & ChrB (0) & ChrB (a) & ChrB (0) &_

ChrB (0) & ChrB (0) & ChrB (1) & ChrB (0)

Response.BinaryWrite ChrB & ChrB (0) & ChrB (0) & ChrB (0) & ChrB (0) & ChrB (0) & ChrB (176) & ChrB (4) &_

ChrB (0) & ChrB (0) & ChrB (a) & ChrB (one) & ChrB (0) & ChrB (0) & ChrB (a) & ChrB (one) &_

ChrB (0) & ChrB (0) & ChrB (0) & ChrB (0) & ChrB (0) & ChrB (0) & ChrB (0) & ChrB (0) &_

ChrB (0) & ChrB (0)

For i = 9 to 0 Step-1 ' line

For II = 0 to 3 ' words

For III = 1 to 10 ' pixel points

If Mid (Vnumberdata (Vcode (ii)), I * + III, 1) = "0" then "produces colored dots, minus a fixed value to make the color darker

Dim a,b,c

A=abs (RND * 256-60)

B=abs (RND * 256-128)

C=abs (RND * 256-60)

Vcolordata (0) = ChrB (a) & ChrB (b) & ChrB (c)

Response.BinaryWrite Vcolordata (Mid vnumberdata (Vcode (ii)), I * + III, 1))

Else

Dim D,e,f ' produces a color background, a lighter color, or a random generation of noise to do the background.

D=abs (RND * 255)

E=abs (RND * 255)

F=abs (RND * 255)

If d+e+f>640 then ' can be modified to adjust background color depth

Vcolordata (1) = ChrB (d) & ChrB (E) & ChrB (f)

Response.BinaryWrite Vcolordata (Mid vnumberdata (Vcode (ii)), I * + III, 1))

Else

Response.BinaryWrite Vcolordata (Mid vnumberdata (Vcode (ii)), I * + III, 1))

End If

End If

Next

Next

Next

End Sub
%>

The above code can be directly saved as a file, such as vcode.asp, and then through the image of the way to call the change file, such as
Finally, it is the "5+6=" such as the form of random numbers added in BMP images, their and need you to calculate after filling in order to achieve the function of validation to prevent the machine from ravaging your site. If you are also concerned about the ASP image verification code, welcome message, let us exchange.
Related Article

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.