ASP generates the BMP image verification code for the sum of numbers

Source: Internet
Author: User
Tags bmp image

Currently, there are many image verification codes on the network. The anti-cracking defense capabilities of those without generating image verification codes are simply vulnerable. Some people directly display specific numbers in the source code of the webpage, then ask the visitor to enter a sum of values, such as 3 + 5 =. There are some new ideas about such verification codes, but unfortunately, they do not play a protection role at all.

Flymorn improved the above new ideas by directly generating Bmp image formats in the form of 3 + 6 = Using asp, and adding and saving the numbers into the session to increase the threshold for cracking; without some knowledge of graphics and images, they cannot be cracked. The Code is as follows:
Copy codeThe Code is 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" 'value range

Dim vColorData (2)

VColorData (0) = "" 'black points must be converted to color points, which are not defined at the moment

VColorData (1) = ChrB (255) & ChrB (255) & ChrB (255) 'White spot

Dim vCode (4), vCodes 'generates a group of arbitrary numbers

For I = 0 To 3

VCode (I) = Int (Rnd * cAmount) 'array equals to total * Random Number

If I = 1 then vCode (I) = "11", the second digit is +

If I = 3 then vCode (I) = "10" 'Fourth digit =

VCodes = vCodes & Mid (cCode, vCode (I) +) 'string equals to string plus subsequent values

Next

Session ("checkcode") = int (Mid (vCodes,) + int (Mid (vCodes,) 'calculates the sum value and assigns it 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"

'Indicates =
VNumberData (10) =

"1111111111111111111111111111111000000001111111111111111111111000000001111111111111111111111111111111"
'Indicates +
VNumberData (11) =

"1111111111111100111111110011111111001111100000000110000000011111001111111100111111110011111111111111"

Response. binaryWrite ChrB (66) & ChrB (77) & ChrB (230) & ChrB (4) & ChrB (0) & ChrB (0) & ChrB (0) & ChrB (0) &_

ChrB (0) & ChrB (0) & ChrB (54) & ChrB (0) & ChrB (0) & ChrB (0) & ChrB (40) & ChrB (0) &_

ChrB (0) & ChrB (0) & ChrB (40) & ChrB (0) & ChrB (0) & ChrB (0) & ChrB (10) & ChrB (0) &_

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

Response. binaryWrite ChrB (24) & ChrB (0) & ChrB (0) & ChrB (0) & ChrB (0) & ChrB (0) & chrb( 176) & ChrB (4) &_

ChrB (0) & ChrB (0) & 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)

For I = 9 To 0 Step-1 'row

For ii = 0 To 3 'Words

For iii = 1 To 10' Pixel

If Mid (vNumberData (vCode (ii), I * 10 + iii, 1) = "0" then' generates a color point, minus a fixed value, which can 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 * 10 + iii, 1 ))

Else

Dim d, e, f' generates a color background. The color is light and noise can be randomly generated as the background.

D = abs (rndx 255)

E = abs (Rnd * 255)

F = abs (rndx 255)

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

VColorData (1) = ChrB (d) & ChrB (e) & ChrB (f)

Response. BinaryWrite vColorData (Mid (vNumberData (vCode (ii), I * 10 + iii, 1 ))

Else

Response. BinaryWrite vColorData (Mid (vNumberData (vCode (ii), I * 10 + 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 use the image method to call the file change, such as , and then verify the value of session (" checkcode ") on the submitted processing page. This code was improved by flymorn. For the original reference code, search for "generate Bmp Images Using ASP" in google or view the URL to find some related information.

Finally, random numbers such as "5 + 6 =" are generated in the bmp image. Their sum needs to be calculated and filled in to achieve the verification function, protect your website from attacks by machines. If you are interested in the asp image verification code, leave a message and let us talk about it.

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.