Verification code Everyone often in the online landing time will see you to 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"
Set Obj=server.createobject ("Shotgraph.image")
X=55 ' picture of the wide
Y=26 ' pictures of high
Obj. CreateImage x,y,8 ' 8 is the color of the picture 8 bits
Obj. SetColor 0,55,126,222
Obj. SetColor 1,255,255,255
Obj. CreatePen "Ps_solid", 1,0
Obj. Setbgcolor 0
Obj. Rectangle 0,0,x-1,y-1
Obj. SetBkMode "Transparent"
Obj. CreateFont "Arial", 136,18,1,false,false,false,false
Obj. SetTextColor 1
Obj. TextOut 5,4,ycode& ""
Img=obj. Gifimage ( -1,1, "")
Response.BinaryWrite (IMG)
For the above code that is to say shotgraph ordinary drawing principle, please refer to: http://www.pconline.com.cn/pcedu/empolder/wz/asp/10204/45207.html
OK, this is done, let's see the effect!
Description, the above generated picture components and code by the poison love to provide, we have any suggestions or better methods, you can go to the Network Forum (http://bbs.wrclub.net) posts, the Network forum always welcome your arrival!
Original source: http://www.wrclub.net/show.aspx?id=1524