[Original] How to Use Image verification code in ASP

Source: Internet
Author: User

Author: loster (OICQ: 181306). If it is reprinted, please do not remove this line. Thank you.

Currently, verification codes are required for login on many websites. Verification codes are generally displayed in the form of images. This improves login security and prevents brute force password cracking. Why use the image display verification code? Imagine that if you only generate a text verification code, the attacker can use a technology similar to a thief to read your page, analyze the verification code, and finally perform brute force guesses. In this way, the Verification Code has no practical significance. Let's talk about how to display the image verification code in ASP.

To display the image verification code in ASP, you must first use the following three files:

Getcode. asp (used to generate image verification code)

Head. Fix (image header)

Body. Fix (image subject)

You may ask, where can I get these files? Don't worry. These files are available in dvbbs7.0. I also learned how to use the image verification code after studying the verification code in dvbbs7.0.

First, let's take a look at the getcode. asp file, which contains several lines like this:

Ados. loadfromfile (server. mappath ("body. Fix "))
Ados1.write Ados. Read (1, 1280)
For I = 0 to 3
Ados. Position = (9-zimg (I) * 320
Ados1.position = I * 320
Ados1.write Ados. Read (1, 320)
Next
Ados. loadfromfile (server. mappath ("head. Fix "))

Have you seen the body. Fix and head. Fix? This refers to their relative location with getcode. asp. If the three files are in the same directory, you can follow the above statements. If not, you need to write out the relative location between them and getcode. asp. For example, if getcode. asp is in the root directory and body. Fix & head. Fix is in the test folder under the root directory, the above Code should be changed:

Ados. loadfromfile (server. mappath ("test/body. Fix "))
Ados1.write Ados. Read (1, 1280)
For I = 0 to 3
Ados. Position = (9-zimg (I) * 320
Ados1.position = I * 320
Ados1.write Ados. Read (1, 320)
Next
Ados. loadfromfile (server. mappath ("test/head. Fix "))

In this way, the image can be displayed normally.

How to call it?

It is very simple, just like this:

You can.

Each time getcode. asp is called, a session is automatically generated, which stores the same four digits as the ones displayed on the verification image. You only need to compare the Received verification code with this session, and then determine whether the verification code is entered correctly. Of course, it is most like this:

If CSTR (TRIM (variable name received) = CSTR (Session ("getcode") then

Response. Write ("OK! ")

Else

Response. Write ("No! ")

End if

So far, it's finished. I hope you will be inspired by this article. Of course, my skills are limited, and errors will inevitably occur in this article. please correct me.

Someone may ask if the image can be modified. The answer is yes. You can check the related articles on the Internet.

Appendix: http://www.loster.net/aspfile/getcode.rar getcode. asp, head. Fix, body. Fix file compressed package

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.