Combination of numbers and letters to generate a picture of the verification Code Xiang solution

Source: Internet
Author: User
Often when you log on the Internet, you will often see that you enter the verification code, there are some words, some pictures, For example chinaren.com alumni in the message, we will see the digital Image verification code; Online about the digital text verification code implementation method of a lot of data, and we are here to introduce the number and the letter of random composition and generate the image of the verification code to achieve the method. Looks very complex, actually very simple, everybody follows me to look down:
First of all, we introduce the design idea, numbers and letters of the random combination of generating verification code, and then the verification code generated pictures, where the "combination of numbers and letters" should be randomly taken out; if it is a specialized digital authentication code, we can achieve this:
Ycodenum=4 ' The number of digits of the verification code, or the number of words
For I=1 to Ycodenum
Randomize ' initialization random number generator
Ycode=ycode&int ((9*rnd)) ' Rnd is a random number, from 0 to 1 of arbitrary real numbers, here gets 0 to 9 integers
Next
Response.Write Ycode ' can output digital verification code (4-bit)
However, we have to make numbers and letters equally random, and here we can use arrays to achieve this effect, as follows:
Ychar= "0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z" to form a string of numbers and uppercase letters
Yc=split (char, ",") ' generates an array of strings
Ycodenum=4
For I=1 to Ycodenum
Randomize
The YCODE=YCODE&YC ((35*rnd)) ' array is generally read from 0, so here's the 35*rnd
Next
Response.Write Ycode

Now see if the output turns out to be a random combination of numbers and letters?
Below see how to generate pictures, this may be some friends know: ASP can not generate pictures, you must use ASP components. Yes, we are using ASP Image component Shotgraph. A little attention, the server is not its own can not use Oh, because you can not install this component.
Component Download Address: http://www.wrclub.net/down.aspx?id=545, as for how to register, here is not much to say, the internet has a lot of information
Let's look at the code that generates the picture:
Ychar= "0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z" to form a string of numbers and uppercase letters
Yc=split (char, ",") ' generates an array of strings
Ycodenum=4
For I=1 to Ycodenum
Randomize
The YCODE=YCODE&YC ((35*rnd)) ' array is generally read from 0, so here's the 35*rnd
Next
Response.Clear
Response.contenttype= "Image/gif"

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.