Code for generating a very good four-digit verification code in ASP-[ASP program]

Source: Internet
Author: User

<%
Call com_creatvalidcode ("validcode ")

Sub com_creatvalidcode (PSN)
'Prohibit caching
Response. expires =-9999
Response. addheader "Pragma", "No-Cache"
Response. addheader "cache-ctrol", "No-Cache"
Response. contenttype = "image/BMP"

Randomize

Dim I, II, III

Const codds = 4' probability of occurrence of miscellaneous
Const camount = 10' text count
Const ccodes = "0123456789"

'Color data (character, background)
Dim vcolordata (1)
Vcolordata (0) = chrb (1) & chrb (52) & chrb (255) 'Blue 1, green 52, red 255 (red)
Vcolordata (1) = chrb (255) & chrb (255) & chrb (255) 'Blue 255, green 255, red 255

'Randomly generated characters
Dim vcode (4), vcodes
For I = 0 to 3
Vcode (I) = int (RND * camount)
Vcodes = vcodes & Mid (cCode, vcode (I) + 1, 1)
Next

'Session ("vcodes") = vcode' record the session
Session ("checkcode") = vcodes 'record the session
'Character data
Dim vnumberdata (35)
Vnumberdata (0) = "1110000111110111101111011110111101001011110100101111010010111101001011110111101111011110111110000111"
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"
'Output image file headers
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)

'Output Image Information Headers
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 'goes through all rows
For II = 0 to 3' goes through all words
For IIi = 1 to 10' goes through all pixels
'Output image data row by row, word by word, and pixel by Pixel
If RND * 99 + 1 <codds then' random generation of miscellaneous
Response. binarywrite vcolordata (0)
Else
Response. binarywrite vcolordata (mid (vnumberdata (vcode (II), I * 10 + III, 1 ))
End if
Next
Next
Next

End sub

'The generated verification code is stored in the session, and it is displayed on the to be referenced.

%>

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.