asp中文数字验证码

< %
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
生成随机四位数字:
       zNum 
=   cint ( 8999 * Rnd + 1000 )
传递给session
       Session(
" GetCode " =  zNum
该for循环是将随机数字放入一个下标3的数组,便于提供给后面的阵列变换
       
dim  zimg( 3 ),NStr
              NStr
= cstr (zNum)
              
For  i = 0   to   3
                     zimg(i)
= cint ( mid (NStr,i + 1 , 1 ))
              
Next
       
dim  Pos

' 定义二个 ADODB.Stream binary对象,作图像数据操作之用:

       
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
' 载入0~9的数字数据10x100的,Gbr的阵列数据,每个320字节,10个数字3200byte
'
BGR一个点,10x10个点一个数字,一个点三个字节(二进制8位,16进制 00~FF)
'
一行10个点 30字节 + 行结束标记 00 00 二字节 32字节,所以一个10x100宽小于长的图像每个数字10x10是320字节
'
长大于宽的则无行结束标记 0000,直接是300字节
这些就是BMP 24bit的数据详细信息了
‘至于头部,也很简单,包含长宽,图像开始标记等等~~才54字节,远没jpg什么的复杂

              Ados.LoadFromFile(Server.mappath(
" body.Fix " ))
              Ados1.write Ados.read(
1280 )
' 第一个for循环,按生成的随机数字顺序从 10X100的数字阵列中提取出相应的四个数字
但是竖排的数字阵列
              
for  i = 0   to   3
                     Ados.Position
= ( 9 - zimg(i)) * 320
                     Ados1.Position
= i * 320
                     Ados1.write ados.read(
320 )
              
next
' 清空已经用完的ADOS的数据,调入替换新的图像头54字节的头文件       
              Ados.LoadFromFile(Server.mappath( " head.fix " ))
              Pos
= lenb(Ados.read())
              Ados.Position
= Pos  ' 指定Pos位置,即可再偏移54字节的位置添加图形数据
第二个for循环,进行数字的阵列变换,由竖排的块转换为横排的数字块
方法是隔320字节抽取4次30字节写入ados对象,再抽取偏移第二行的图像数据
30字节是因为bmp 宽大于长时无00 00的行结束标记
              
for  i = 0   to   9  step  1
                     
for  j = 0   to   3
                            Ados1.Position
= i * 32 + j * 320
                            Ados.Position
= Pos + 30 * j + i * 120
                            Ados.write ados1.read(
30 )
                     
next
              
next
              Ados.Position
= 0
response.BinaryWrite直接向客户端发送图像数据
              Response.ContentType 
=   " image/BMP "
              Response.BinaryWrite Ados.read()
              Ados.Close:
set  Ados = nothing
              Ados1.Close:
set  Ados1 = nothing
End Function
%
>

 

 

< %
=  Request.form( " c " )

' 如果可以输入小写的数字,请把下面三行注释掉
  for  ii  =   0   to   9
 c 
=   Replace (c, Cstr (ii), "" )
 
next

 c 
=   Replace (c, " " , " 0 " )
 c 
=   Replace (c, " " , " 1 " )
 c 
=   Replace (c, " " , " 2 " )
 c 
=   Replace (c, " " , " 3 " )
 c 
=   Replace (c, " " , " 4 " )
 c 
=   Replace (c, " " , " 5 " )
 c 
=   Replace (c, " " , " 6 " )
 c 
=   Replace (c, " " , " 7 " )
 c 
=   Replace (c, " " , " 8 " )
 c 
=   Replace (c, " " , " 9 " )

if   Cstr (c)  <>   Cstr (Session( " validateCode " ))  then
 Response.write (
" 验证码不正确 " )
else
 
' 这里处理表单
end   if
%
>

你可能感兴趣的:(c,timer,function,session,asp,byte)