ASP加法驗證碼代碼
網上的驗證碼有許多種,如:數字驗證碼,字符驗證碼,漢字驗證碼,加法驗證碼,拖動驗證碼,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實現加法驗證碼的關鍵代碼,有興趣的朋友,還可以改成為其他的運算,比如乘法,減法,乘方等。