Color verification code creation

Source: Internet
Author: User

To read this code, you must understand the object ADODB. Stream for operating binary data in ASP! This program mainly uses ADODB. stream, if you have this foundation, you can further add more functions, such as adding the miscellaneous, gradient background color, number row and column misplacement, stroke short points, to improve the possibility of OCR recognition. There is no good recognition engine yet. Yesterday I downloaded a verification code 90% that can recognize images! Recognize 4321 to 89910, so the image code is safer.

We can see brute-force cracking methods on the Internet, if I use an image additional code + prohibit external submissions + 10 wrong password mails to my account + 50 wrong passwords, and a zombie IP address + 10 seconds of anti-Refresh Interval registration page, + External submission is prohibited on the login page. In this way, brute-force cracking should be useless.

ASP file: code. asp
Data File: body. Fix, head. Fix
Usage:

Response. Buffer = true
Numcode

Function numcode ()
Response. expires =-1
Response. addheader "Pragma", "No-Cache"
Response. addheader "cache-ctrol", "No-Cache"
Dim znum, I, j
Dim Ados, ados1
Randomize Timer
Generate four random numbers:
Znum = CINT (8999 * RND + 1000)
Pass to session
Session ("getcode") = znum
This for loop puts random numbers into an array with subscript 3, which is convenient for array transformation.
Dim zimg (3), NSTR
NSTR = CSTR (znum)
For I = 0 to 3
Zimg (I) = CINT (mid (NSTR, I + 1, 1 ))
Next
Dim POS

'Define two ADODB. Stream binary objects for image data operations:

Set Ados = server. Createobject ("ADODB. Stream ")
Ados. mode = 3
Ados. type = 1
Ados. Open
Set ados1 = server. Createobject ("ADODB. Stream ")
Ados1.mode = 3
Ados1.type = 1
Ados1.open
'Load 0 ~ 9. The array data of GBR is 10x320, each of which is 3200 bytes and 10 digits are bytes.
'Bgr: one point, 10x10 points, one digit, three bytes at a point (Binary 8-bit, hexadecimal 00 ~ Ff)
'Line 10 Points 30 byte + Line End mark 00 00 two byte 32 byte, so a 10x320 width less than long image each number 10x10 is byte
'When the width is greater than 0000, the end of the row is 300 bytes.
These are the detailed information of the BMP 24bit data.
'As for the header, it is also very simple, including the length and width, starting to mark the image, and so on ~~ Only 54 bytes, far less complicated than jpg or anything

Ados. loadfromfile (server. mappath ("body. Fix "))
Ados1.write Ados. Read (1, 1280)
'In the first for loop, four numbers are extracted from the array of 10 X numbers in the order of the generated random numbers.
But the number array in the vertical bar
For I = 0 to 3
Ados. Position = (9-zimg (I) * 320
Ados1.position = I * 320
Ados1.write Ados. Read (1, 320)
Next
'Clear the data of the used Ados and call it to replace the 54-byte header file of the new image header.
Ados. loadfromfile (server. mappath ("head. Fix "))
Pos = lenb (Ados. Read ())
Ados. Position = pos': Specifies the position of the POs, and the image data can be added at a 54-byte offset.
The second for loop is used to convert the array of numbers from the vertical bars to the horizontal bars.
The method is to extract 4 times and write 30 bytes to the Ados object every 320 bytes, and then extract the image data that is offset from the second row.
30 bytes because BMP is larger than long without the end mark of 00 00
For I = 0 to 9 Step 1
For J = 0 to 3
Ados1.position = I x 32 + J x 320
Ados. Position = POS + 30 * j + I * 120
Ados. Write ados1.read (30)
Next
Next
Ados. Position = 0
Response. binarywrite directly sends image data to the client
Response. contenttype = "image/BMP"
Response. binarywrite Ados. Read ()
Ados. Close: Set Ados = nothing
Ados1.close: Set ados1 = nothing
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.