如何给ASP网站加入验证码完全点的

如何给ASP网站加入验证码完全点的... 如何给ASP网站加入验证码完全点的 展开
 我来答
花满楼灬煜
2015-12-25 · TA获得超过107个赞
知道答主
回答量:29
采纳率:100%
帮助的人:18.8万
展开全部
1、index.asp
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<form action="submit.asp" method="post" name="form1">

请输入验证码<input type="text" value="" name="yanzheng" />
<img src="yanzhengma.asp">
<input type="submit" />
</form>
</body>
</html>

2、yanzhengma.asp
<%
Call Com_CreatValidCode("ValidCode")
Sub Com_CreatValidCode(pSN)
Response.Expires = -9999
Response.AddHeader "Pragma","no-cache"
Response.AddHeader "cache-ctrol","no-cache"
Response.ContentType = "Image/BMP"
Randomize
Dim i, ii, iii
Const cOdds = 8 '杂点出现的机率
Const cAmount = 10 '文字数量
Const cCode = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
'颜色的数据(字符,背景)
Dim vColorData(1)
vColorData(0) = ChrB(0) & ChrB(0) & ChrB(255) '蓝0,绿0,红0(黑色)
vColorData(1) = ChrB(235) & ChrB(235) & ChrB(235) '蓝250,绿236,红211(浅蓝色)
'随机产生字符
Dim vCode(4), vCodes
For i = 0 To 3
vCode(i) = Int(Rnd * cAmount)
vCodes = vCodes & Mid(cCode, vCode(i) + 1, 1)
Next
session("ddyanzheng")=vCodes '记录入Session
'字符的数据
Dim vNumberData(35)
vNumberData(0) = "1110000111110111101111011110111101001011110100101111010010111101001011110111101111011110111110000111"
vNumberData(1) = "1111011111110001111111110111111111011111111101111111110111111111011111111101111111110111111100000111"
vNumberData(2) = "1110000111110111101111011110111111111011111111011111111011111111011111111011111111011110111100000011"
vNumberData(3) = "1110000111110111101111011110111111110111111100111111111101111111111011110111101111011110111110000111"
vNumberData(4) = "1111101111111110111111110011111110101111110110111111011011111100000011111110111111111011111111000011"
vNumberData(5) = "1100000011110111111111011111111101000111110011101111111110111111111011110111101111011110111110000111"
vNumberData(6) = "1111000111111011101111011111111101111111110100011111001110111101111011110111101111011110111110000111"
vNumberData(7) = "1100000011110111011111011101111111101111111110111111110111111111011111111101111111110111111111011111"
vNumberData(8) = "1110000111110111101111011110111101111011111000011111101101111101111011110111101111011110111110000111"
vNumberData(9) = "1110001111110111011111011110111101111011110111001111100010111111111011111111101111011101111110001111"
vNumberData(10) = "1111011111111101111111101011111110101111111010111111101011111100000111110111011111011101111000100011"
vNumberData(11) = "1000000111110111101111011110111101110111110000111111011101111101111011110111101111011110111000000111"
vNumberData(12) = "1110000011110111101110111110111011111111101111111110111111111011111111101111101111011101111110001111"
vNumberData(13) = "1000001111110111011111011110111101111011110111101111011110111101111011110111101111011101111000001111"
vNumberData(14) = "1000000111110111101111011011111101101111110000111111011011111101101111110111111111011110111000000111"
vNumberData(15) = "1000000111110111101111011011111101101111110000111111011011111101101111110111111111011111111000111111"
vNumberData(16) = "1110000111110111011110111101111011111111101111111110111111111011100011101111011111011101111110001111"
vNumberData(17) = "1000100011110111011111011101111101110111110000011111011101111101110111110111011111011101111000100011"
vNumberData(18) = "1100000111111101111111110111111111011111111101111111110111111111011111111101111111110111111100000111"
vNumberData(19) = "1110000011111110111111111011111111101111111110111111111011111111101111111110111110111011111000011111"
vNumberData(20) = "1000100011110111011111011011111101011111110001111111010111111101101111110110111111011101111000100011"
vNumberData(21) = "1000111111110111111111011111111101111111110111111111011111111101111111110111111111011110111000000011"
vNumberData(22) = "1000100011110010011111001001111100100111110101011111010101111101010111110101011111010101111001010011"
vNumberData(23) = "1000100011110011011111001101111101010111110101011111010101111101100111110110011111011001111000110111"
vNumberData(24) = "1110001111110111011110111110111011111011101111101110111110111011111011101111101111011101111110001111"
vNumberData(25) = "1000000111110111101111011110111101111011110000011111011111111101111111110111111111011111111000111111"
vNumberData(26) = "1110001111110111011110111110111011111011101111101110111110111011111011101001101111011001111110001011"
vNumberData(27) = "1000001111110111011111011101111101110111110000111111010111111101101111110110111111011101111000110011"
vNumberData(28) = "1110000011110111101111011110111101111111111001111111111001111111111011110111101111011110111100000111"
vNumberData(29) = "1000000011101101101111110111111111011111111101111111110111111111011111111101111111110111111110001111"
vNumberData(30) = "1000100011110111011111011101111101110111110111011111011101111101110111110111011111011101111110001111"
vNumberData(31) = "1000100011110111011111011101111101110111111010111111101011111110101111111010111111110111111111011111"
vNumberData(32) = "1001010011110101011111010101111101010111110101011111001001111110101111111010111111101011111110101111"
vNumberData(33) = "1000100011110111011111101011111110101111111101111111110111111110101111111010111111011101111000100011"
vNumberData(34) = "1000100011110111011111011101111110101111111010111111110111111111011111111101111111110111111110001111"
vNumberData(35) = "1100000011110111011111111101111111101111111110111111110111111111011111111011111111101110111100000011"
'输出图像文件头
Response.BinaryWrite ChrB(66) & ChrB(77) & ChrB(230) & ChrB(4) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) &_
ChrB(0) & ChrB(0) & ChrB(54) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(40) & ChrB(0) &_
ChrB(0) & ChrB(0) & ChrB(40) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(10) & ChrB(0) &_
ChrB(0) & ChrB(0) & ChrB(1) & ChrB(0)
'输出图像信息头
Response.BinaryWrite ChrB(24) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(176) & ChrB(4) &_
ChrB(0) & ChrB(0) & ChrB(18) & ChrB(11) & ChrB(0) & ChrB(0) & ChrB(18) & ChrB(11) &_
ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) &_
ChrB(0) & ChrB(0)
For i = 9 To 0 Step -1 '历经所有行
For ii = 0 To 3 '历经所有字
For iii = 1 To 10 '历经所有像素
'逐行、逐字、逐像素地输出图像数据
If Rnd * 99 + 1 < cOdds Then '随机生成杂点
Response.BinaryWrite vColorData(0)
Else Response.BinaryWrite vColorData(Mid(vNumberData(vCode(ii)), i * 10 + iii, 1))
End If
Next
Next
Next
End Sub%>
3、在submit.asp验证验证码输入的是否正确
<%if trim(server.HTMLEncode(Request.Form("yanzheng"))) <> session("ddyanzheng") then
response.Write("验证码不正确")
'response.Redirect("index.asp")
else
response.Write("ok")
end if
%>
开发者之路
2010-05-06 · TA获得超过910个赞
知道大有可为答主
回答量:2031
采纳率:0%
帮助的人:937万
展开全部
要做验证码,首先要有一个获取验证码的文件,这个文件一般命名为getcode.asp或者其他的,这样的文件一般不用我们自己写,随便找一个下载下来就可以了,比如楼上的就是这样的一个文件.
然后在你需要显示验证码的地方,这样写就可以了.
<img src="inc/getcode.asp" alt="验证码,看不清楚?请点击刷新验证码" height="10" onClick="this.src='Inc/getcode.asp'" />
看到了吗?用一个img来加械这个getcode.asp页面,就自动的产生验证码了.
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
wuqiao5257
2010-05-06 · TA获得超过2090个赞
知道大有可为答主
回答量:776
采纳率:100%
帮助的人:1325万
展开全部
新建一个verifycode.asp文件,里面的代码为下面的:
<%
Response.Expires=0
Dim RndNumber,RndNumberStr,N,Rs,site_verCookies
If RndNumber = "" or isNumeric(RndNumber) = 0 Then RndNumber = 0
If RndNumber = 0 Then
RndNumber = (Fix(Timer) mod 9999) * 999
End If
RndNumberStr = Right("000" & RndNumber,4)
Session("Verifycode") = RndNumberStr
DisplayBMP
'*****************************************************************
' 验证码显示函数
'*****************************************************************
Sub DisplayBMP
Response.Expires = -9999
Response.AddHeader "Pragma","no-cache"
Response.AddHeader "cache-ctrol","no-cache"
Response.ContentType = "Image/BMP"

Randomize

Dim i, ii, iii

Const cOdds = 3 '杂点出现几率
Const cAmount = 36 ' 文字数量
Const cCode = "0123456789"

Dim vColorData(1)
vColorData(0) = ChrB(0) & ChrB(0) & ChrB(0) ' 蓝0,绿0,红0(黑色)
vColorData(1) = ChrB(255) & ChrB(255) & ChrB(255) ' 蓝250,绿236,红211(浅蓝色)

Dim vCode(4)
For i = 0 To 3
vCode(i) = Mid(RndNumberStr,i + 1,1)
Next

Dim ND(35)
ND(0) = "1110000111110111101111011110111101001011110100101111010010111101001011110111101111011110111110000111"
ND(1) = "1111011111110001111111110111111111011111111101111111110111111111011111111101111111110111111100000111"
ND(2) = "1110000111110111101111011110111111111011111111011111111011111111011111111011111111011110111100000011"
ND(3) = "1110000111110111101111011110111111110111111100111111111101111111111011110111101111011110111110000111"
ND(4) = "1111101111111110111111110011111110101111110110111111011011111100000011111110111111111011111111000011"
ND(5) = "1100000011110111111111011111111101000111110011101111111110111111111011110111101111011110111110000111"
ND(6) = "1111000111111011101111011111111101111111110100011111001110111101111011110111101111011110111110000111"
ND(7) = "1100000011110111011111011101111111101111111110111111110111111111011111111101111111110111111111011111"
ND(8) = "1110000111110111101111011110111101111011111000011111101101111101111011110111101111011110111110000111"
ND(9) = "1110001111110111011111011110111101111011110111001111100010111111111011111111101111011101111110001111"
ND(10) = "1111011111111101111111101011111110101111111010111111101011111100000111110111011111011101111000100011"
ND(11) = "1000000111110111101111011110111101110111110000111111011101111101111011110111101111011110111000000111"
ND(12) = "1110000011110111101110111110111011111111101111111110111111111011111111101111101111011101111110001111"
ND(13) = "1000001111110111011111011110111101111011110111101111011110111101111011110111101111011101111000001111"
ND(14) = "1000000111110111101111011011111101101111110000111111011011111101101111110111111111011110111000000111"
ND(15) = "1000000111110111101111011011111101101111110000111111011011111101101111110111111111011111111000111111"
ND(16) = "1110000111110111011110111101111011111111101111111110111111111011100011101111011111011101111110001111"
ND(17) = "1000100011110111011111011101111101110111110000011111011101111101110111110111011111011101111000100011"
ND(18) = "1100000111111101111111110111111111011111111101111111110111111111011111111101111111110111111100000111"
ND(19) = "1110000011111110111111111011111111101111111110111111111011111111101111111110111110111011111000011111"
ND(20) = "1000100011110111011111011011111101011111110001111111010111111101101111110110111111011101111000100011"
ND(21) = "1000111111110111111111011111111101111111110111111111011111111101111111110111111111011110111000000011"
ND(22) = "1000100011110010011111001001111100100111110101011111010101111101010111110101011111010101111001010011"
ND(23) = "1000100011110011011111001101111101010111110101011111010101111101100111110110011111011001111000110111"
ND(24) = "1110001111110111011110111110111011111011101111101110111110111011111011101111101111011101111110001111"
ND(25) = "1000000111110111101111011110111101111011110000011111011111111101111111110111111111011111111000111111"
ND(26) = "1110001111110111011110111110111011111011101111101110111110111011111011101001101111011001111110001011"
ND(27) = "1000001111110111011111011101111101110111110000111111010111111101101111110110111111011101111000110011"
ND(28) = "1110000011110111101111011110111101111111111001111111111001111111111011110111101111011110111100000111"
ND(29) = "1000000011101101101111110111111111011111111101111111110111111111011111111101111111110111111110001111"
ND(30) = "1000100011110111011111011101111101110111110111011111011101111101110111110111011111011101111110001111"
ND(31) = "1000100011110111011111011101111101110111111010111111101011111110101111111010111111110111111111011111"
ND(32) = "1001010011110101011111010101111101010111110101011111001001111110101111111010111111101011111110101111"
ND(33) = "1000100011110111011111101011111110101111111101111111110111111110101111111010111111011101111000100011"
ND(34) = "1000100011110111011111011101111110101111111010111111110111111111011111111101111111110111111110001111"
ND(35) = "1100000011110111011111111101111111101111111110111111110111111111011111111011111111101110111100000011"

' 输出图像文件头
Response.BinaryWrite ChrB(66) & ChrB(77) & ChrB(230) & ChrB(4) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) &_
ChrB(0) & ChrB(0) & ChrB(54) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(40) & ChrB(0) &_
ChrB(0) & ChrB(0) & ChrB(40) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(10) & ChrB(0) &_
ChrB(0) & ChrB(0) & ChrB(1) & ChrB(0)

' 输出图像信息头
Response.BinaryWrite ChrB(24) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(176) & ChrB(4) &_
ChrB(0) & ChrB(0) & ChrB(18) & ChrB(11) & ChrB(0) & ChrB(0) & ChrB(18) & ChrB(11) &_
ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) &_
ChrB(0) & ChrB(0)

For i = 9 To 0 Step -1
For ii = 0 To 3
For iii = 1 To 10
If Rnd * 99 + 1 < cOdds Then
Response.BinaryWrite vColorData(0)
Else
Response.BinaryWrite vColorData(Mid(ND(vCode(ii)), i * 10 + iii, 1))
End If
Next
Next
Next
End Sub
%>
然后在你需要验证码的地方用下面的方法
<tr>
<td height="30" align="right">验证码:</td>
<td height="30"><input type=text name="verifycode" maxLength=4 size="6" tabindex="3" class="textbox" alt="请在此输入验证码,看不清楚请点击图片刷新">
<font color=red> <-请输入验证码</font> <IMG width="50" height="21" style="cursor:hand;" src="verifycode.asp?n=<%=Timer%>" onClick="this.src=this.src;" align="absmiddle" alt="看不清楚,点击图片刷新"></td>
</tr>

验证函数为下面的:
<%
if Trim(Request.Form("Verifycode"))<>Trim(Session("Verifycode")) then
%>
<script language=javascript>
alert('您输入的认证码不对,请重新输入!')
window.history.go(-1)
</script>
<%
response.end
end if
%>
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式