在Z-BLOG可用的新版ASP的GIF验证码[V70404]

2018-09-06 13:03

阅读:355

  复制下面代码,存为c_validcode.asp上传到function下就可以了
复制代码 代码如下:
<%@CODEPAGE=65001%>
<%
///////////////////////////////////////////////////////////////////////////////
//Z-Blog
//作者:朱煊(zx.asd),sipo
//版权所有:RainbowSoftStudio
//技术支持
//单元名称:c_validcode.asp
//开始时间:2007-4-4
//最后修改:2007-4-4
//备注:
///////////////////////////////////////////////////////////////////////////////
%>
<%OptionExplicit%>
<%OnErrorResumeNext%>
<!--#includefile=../c_option.asp-->
<!--#includefile=../function/c_function.asp-->
<%
.VerifyCodeGetVerifyNumber,False
ClassCom_GifCode_Class
PublicNoisy,Count,Width,Height,Angle,Offset,Border
PrivateGraph(),Margin(3)
PrivateSubClass_Initialize()
Randomize
Noisy=7干扰点出现的概率
Count=5字符数量
Width=60图片宽度
Height=20图片高度
Angle=3角度随机变化量
Offset=10偏移随机变化量
Border=2边框大小
EndSub
PublicFunctionCreate(str)
Dimi
DimvIndex
ReDimGraph(Width-1,Height-1)
Fori=0ToCount-1
vIndex=CInt(Mid(str,i+1,1)-1)
SetDrawvIndex,i
Next
EndFunction

SubSetDot(pX,pY)
IfpX*(Width-pX-1)>=0AndpY*(Height-pY-1)>=0Then
Graph(pX,pY)=1
EndIf
EndSub

PublicSubSetDraw(pIndex,pNumber)
字符数据字典
IfpIndex=-1ThenpIndex=9
DimDotData(9)
DotData(0)=Array(30,15,50,1,50,100)
DotData(1)=Array(1,34,30,1,71,1,100,34,1,100,93,100,100,86)
DotData(2)=Array(1,1,100,1,42,42,100,70,50,100,1,70)
DotData(3)=Array(100,73,6,73,75,6,75,100)
DotData(4)=Array(100,1,1,1,1,50,50,35,100,55,100,80,50,100,1,95)
DotData(5)=Array(100,20,70,1,20,1,1,30,1,80,30,100,70,100,100,80,100,60,70,50,30,50,1,60)
DotData(6)=Array(6,26,6,6,100,6,53,100)
DotData(7)=Array(100,30,100,20,70,1,30,1,1,20,1,30,100,70,100,80,70,100,30,100,1,80,1,70,100,30)
DotData(8)=Array(1,80,30,100,80,100,100,70,100,20,70,1,30,1,1,20,1,40,30,50,70,50,100,40)
DotData(9)=Array(100,20,70,1,20,1,1,30,1,80,30,100,70,100,100,80,100,60,90,20,80,3)


DimvExtent:vExtent=Width/Count
Margin(0)=Border+vExtent*(Rnd*Offset)/100+Margin(1)
Margin(1)=vExtent*(pNumber+1)-Border-vExtent*(Rnd*Offset)/100
Margin(2)=Border+Height*(Rnd*Offset)/100
Margin(3)=Height-Border-Height*(Rnd*Offset)/100

DimvStartX,vEndX,vStartY,vEndY
DimvWidth,vHeight,vDX,vDY,vDeltaT
DimvAngle,vLength

vWidth=Int(Margin(1)-Margin(0))
vHeight=Int(Margin(3)-Margin(2))
vStartX=Int((DotData(pIndex)(0)-1)*vWidth/100)
vStartY=Int((DotData(pIndex)(1)-1)*vHeight/100)

Dimi,j
Fori=1ToUBound(DotData(pIndex),1)/2
IfDotData(pIndex)(2*i-2)<>0AndDotData(pIndex)(2*i)<>0Then
vEndX=(DotData(pIndex)(2*i)-1)*vWidth/100
vEndY=(DotData(pIndex)(2*i+1)-1)*vHeight/100
vDX=vEndX-vStartX
vDY=vEndY-vStartY
IfvDX=0Then
vAngle=Sgn(vDY)*3.14/2
Else
vAngle=Atn(vDY/vDX)
EndIf
IfSin(vAngle)=0Then
vLength=vDX
Else
vLength=vDY/Sin(vAngle)
EndIf
vAngle=vAngle+(Rnd-0.5)*2*Angle*3.14*2/100
vDX=Int(Cos(vAngle)*vLength)
vDY=Int(Sin(vAngle)*vLength)
IfAbs(vDX)>Abs(vDY)ThenvDeltaT=Abs(vDX)ElsevDeltaT=Abs(vDY)
Forj=1TovDeltaT
SetDotMargin(0)+vStartX+j*vDX/vDeltaT,Margin(2)+vStartY+j*vDY/vDeltaT
Next
vStartX=vStartX+vDX
vStartY=vStartY+vDY
EndIf
Next
EndSub

PublicSubOutput()
Response.Expires=-9999
Response.AddHeaderpragma,no-cache
Response.AddHeadercache-ctrol,no-cache
Response.BinaryWriteChrB(Asc(G))&ChrB(Asc(I))&ChrB(Asc(F))
Response.BinaryWriteChrB(Asc(8))&ChrB(Asc(9))&ChrB(Asc(a))
Response.BinaryWriteChrB(WidthMod256)&ChrB((Width\256)Mod256)
Response.BinaryWriteChrB(HeightMod256)&ChrB((Height\256)Mod256)
Response.BinaryWriteChrB(128)&ChrB(0)&ChrB(0)
Response.BinaryWriteChrB(250)&ChrB(250)&ChrB(250)
Response.BinaryWriteChrB(0)&ChrB(0)&ChrB(0)
Response.BinaryWriteChrB(Asc(,))
Response.BinaryWriteChrB(0)&ChrB(0)&ChrB(0)&ChrB(0)
Response.BinaryWriteChrB(WidthMod256)&ChrB((Width\256)Mod256)
Response.BinaryWriteChrB(HeightMod256)&ChrB((Height\256)Mod256)
Response.BinaryWriteChrB(0)&ChrB(7)&ChrB(255)

Dimx,y,i:i=0
Fory=0ToHeight-1
Forx=0ToWidth-1
IfRnd<Noisy/100Then
Response.BinaryWriteChrB(1-Graph(x,y))
ElseIfx*(x-Width)=0Ory*(y-Height)=0Then
Response.BinaryWriteChrB(Graph(x,y))
ElseIfGraph(x-1,y)=1OrGraph(x,y)OrGraph(x,y-1)=1Then
Response.BinaryWriteChrB(1)
Else
Response.BinaryWriteChrB(0)
EndIf

If(y*Width+x+1)Mod126=0Then
Response.BinaryWriteChrB(128)
i=i+1
EndIf
If(y*Width+x+i+1)Mod255=0Then
If(Width*Height-y*Width-x-1)>255Then
Response.BinaryWriteChrB(255)
Else
Response.BinaryWriteChrB(Width*HeightMod255)
EndIf
EndIf
Next
Next
Response.BinaryWriteChrB(128)&ChrB(0)&ChrB(129)&ChrB(0)&ChrB(59)
EndSub
EndClass
DimmCode
Dimcode
SetmCode=NewCom_GifCode_Class
mCode.Create(GetVerifyNumber)
mCode.Output()
SetmCode=Nothing
%>

由于原验证码过于简单,导致zblogger们饱受垃圾评论与引用之苦,下一版本将集成该验证码。
该验证码是根据网络上流传的一个源代码修改而来。
另,近期新的反垃圾评论与引用工具将与大家见面。


评论


亲,登录后才可以留言!