网上的验证码有许多种,如:数字验证码,字符验证码,汉字验证码,加法验证码,拖动验证码,12306那种验证码等等,这里介绍加法验证码。
将验证码改为加法运算,比如验证码显示“25+64等于?”,那么输入“91”就能通过验证。
来看看效果图对比:字符验证码:0561 → 加法验证码:90+93=?
优点:
①与纯字符验证码相比,本程序效防止了绝大部分(99%以上)广告机的自动识别。即使是中文验证码, 也能被市面上的部分广告机识别。
②与中文验证码相比,避免了用户输入用户名密码验证码的.时候需要切换输入法的麻烦。
说明:该程序需要网站空间支持ASPJpeg组件、楷体_GB2312字体。
代码如下:
<%
Const FontColor = &H000000 ' 字体颜色
Const BgColor = &HFFCCFF ' 背景颜色
Call CreatValidCode("GetCode")
Sub CreatValidCode(pSN)
Dim x, Jpeg
Randomize
x = Array(1+Int(Rnd()*9), Int(Rnd()*10), 1+Int(Rnd()*9), Int(Rnd()*10), 0, 0, "+")
x(4) = x(0)*10 + x(1)
x(5) = x(2)*10 + x(3)
'Session(pSN) = CStr(Eval(x(4) & x(6) & x(5)))
Session(pSN) = CStr(x(4) + x(5))
Set Jpeg = Server.CreateObject("Persits.Jpeg")
J 100,20,BgColor
Jity=100
With Jas
= True
= 16
tion = 0
ly = "楷体_GB2312"
r = FontColor
tText 4, 3, CStr(x(0))
tText 14, 3, CStr(x(1))
tText 26, 3, x(6)
tText 38, 3, CStr(x(2))
tText 48, 3, CStr(x(3))
tion = 15
tText 55, 3, "等"
tText 70, 3, "于"
tText 85, 3, "?"
End With
'禁止缓存
entType = "image/jpeg"
res = -9999
eader "pragma", "no-cache"
eader "cache-ctrol", "no-cache"
eader "Content-Disposition","inline; filename=vcode.jpg"
Jpeg.SendBinary
Je
Set Jpeg = Nothing
End Sub
%>
以上就是关于asp实现加法验证码的关键代码,有兴趣的朋友,还可以改成为其他的运算,比如乘法,减法,乘方等。