标题:运行时验证码不能正常出现
只看楼主
nbsyf
Rank: 1
等 级:新手上路
帖 子:382
专家分:0
注 册:2006-7-31
结帖率:90.7%
已结贴  问题点数:20 回复次数:5 
运行时验证码不能正常出现
以下checkcode.asp是出现验证码的程序,请教它错在什么地方,使在运行时不能出现正常图像,而是出现一个叉号。
<%
Dim a(10,10)

a(0,1) = "0x3c" '数字0
a(0,2) = "0x66"
a(0,3) = "0xc3"
a(0,4) = "0xc3"
a(0,5) = "0xc3"
a(0,6) = "0xc3"
a(0,7) = "0xc3"
a(0,8) = "0xc3"
a(0,9) = "0x66"
a(0,10)= "0x3c"

a(1,1) = "0x18"    '数字1
a(1,2) = "0x1c"
a(1,3) = "0x18"
a(1,4) = "0x18"
a(1,5) = "0x18"
a(1,6) = "0x18"
a(1,7) = "0x18"
a(1,8) = "0x18"
a(1,9) = "0x18"
a(0,10)= "0x7e"


a(2,1) = "0x3c" '数字2
a(2,2) = "0x66"
a(2,3) = "0x60"
a(2,4) = "0x60"
a(2,5) = "0x30"
a(2,6) = "0x18"
a(2,7) = "0x0c"
a(2,8) = "0x06"
a(2,9) = "0x06"
a(2,10)= "0x7e"

a(3,1) = "0x3c" '数字3
a(3,2) = "0x66"
a(3,3) = "0xc0"
a(3,4) = "0x60"
a(3,5) = "0x1c"
a(3,6) = "0x60"
a(3,7) = "0xc0"
a(3,8) = "0xc0"
a(3,9) = "0x66"
a(3,10)= "0x38"

a(4,1) = "0x38" '数字4
a(4,2) = "0x3c"
a(4,3) = "0x36"
a(4,4) = "0x33"
a(4,5) = "0x33"
a(4,6) = "0x33"
a(4,7) = "0xff"
a(4,8) = "0x30"
a(4,9) = "0x30"
a(4,10)= "0xfe"

a(5,1) = "0xfe" '数字5
a(5,2) = "0xfe"
a(5,3) = "0x06"
a(5,4) = "0x06"
a(5,5) = "0x3e"
a(5,6) = "0x60"
a(5,7) = "0xc0"
a(5,8) = "0xc3"
a(5,9) = "0x66"
a(5,10)= "0x3c"

a(6,1) = "0x60" '数字6
a(6,2) = "0x30"
a(6,3) = "0x18"
a(6,4) = "0x0c"
a(6,5) = "0x3e"
a(6,6) = "0x63"
a(6,7) = "0xc3"
a(6,8) = "0xc3"
a(6,9) = "0x66"
a(6,10) ="0x3c"

a(7,1) = "0xff" '数字7
a(7,2) = "0xc0"
a(7,3) = "0x60"
a(7,4) = "0x30"
a(7,5) = "0x18"
a(7,6) = "0x18"
a(7,7) = "0x18"
a(7,8) = "0x18"
a(7,9) = "0x18"
a(7,10)= "0x18"

a(8,1) = "0x3c" '数字8
a(8,2) = "0x66"
a(8,3) = "0xc3"
a(8,4) = "0x66"
a(8,5) = "0x3c"
a(8,6) = "0x66"
a(8,7) = "0xc3"
a(8,8) = "0xc3"
a(8,9) = "0x66"
a(8,10)= "0x3c"

a(9,1) = "0x3c" '数字9
a(9,2) = "0x66"
a(9,3) = "0xc3"
a(9,4) = "0xc3"
a(9,5) = "0x66"
a(9,6) = "0x3c"
a(9,7) = "0x18"
a(9,8) = "0x0c"
a(9,9) = "0x06"
a(9,10)= "0x03"

%>
   


<%
     '### To encrypt/decrypt include this code in your page
     '### strMyEncryptedString = EncryptString(strString)
     '### strMyDecryptedString = DeCryptString(strMyEncryptedString)
     '### You are free to use this code as long as credits remain in place
     '### also if you improve this code let me know.
     
     Private Function EncryptString(strString)
     '####################################################################
     '### Crypt Function (C) 2001 by Slavic Kozyuk grindkore@ ###
     '### Arguments: strString <--- String you wish to encrypt ###
     '### Output: Encrypted HEX string ###
     '####################################################################
     
     Dim CharHexSet, intStringLen, strTemp, strRAW, i, intKey, intOffSet
     Randomize Timer
     
     intKey = Round((RND * 1000000) + 1000000) '##### Key Bitsize
     intOffSet = Round((RND * 1000000) + 1000000) '##### KeyOffSet Bitsize
     
     If IsNull(strString) = False Then
     strRAW = strString
     intStringLen = Len(strRAW)
     
     For i = 0 to intStringLen - 1
     strTemp = Left(strRAW, 1)
     strRAW = Right(strRAW, Len(strRAW) - 1)
     CharHexSet = CharHexSet & Hex(Asc(strTemp) * intKey)& Hex(intKey)
     Next
     
     EncryptString = CharHexSet & "|" & Hex(intOffSet + intKey) & "|" & Hex(intOffSet)
     Else
     EncryptString = ""
     End If
     End Function
     
     
     
     
     Private Function DeCryptString(strCryptString)
     '####################################################################
     '### Crypt Function (C) 2001 by Slavic Kozyuk grindkore@ ###
     '### Arguments: Encrypted HEX stringt ###
     '### Output: Decrypted ASCII string ###
     '####################################################################
     '### Note this function uses HexConv() and get_hxno() functions ###
     '### so make sure they are not removed ###
     '####################################################################
     
     Dim strRAW, arHexCharSet, i, intKey, intOffSet, strRawKey, strHexCrypData
     
     
     strRawKey = Right(strCryptString, Len(strCryptString) - InStr(strCryptString, "|"))
     intOffSet = Right(strRawKey, Len(strRawKey) - InStr(strRawKey,"|"))
     intKey = HexConv(Left(strRawKey, InStr(strRawKey, "|") - 1)) - HexConv(intOffSet)
     strHexCrypData = Left(strCryptString, Len(strCryptString) - (Len(strRawKey) + 1))
     
     
     arHexCharSet = Split(strHexCrypData, Hex(intKey))
     
     For i=0 to UBound(arHexCharSet)
     strRAW = strRAW & Chr(HexConv(arHexCharSet(i))/intKey)
     Next
     
     DeCryptString = strRAW
     End Function
     
     
     
     Private Function HexConv(hexVar)
     Dim hxx, hxx_var, multiply
     IF hexVar <> "" THEN
     hexVar = UCASE(hexVar)
     hexVar = StrReverse(hexVar)
     DIM hx()
     REDIM hx(LEN(hexVar))
     hxx = 0
     hxx_var = 0
     FOR hxx = 1 TO LEN(hexVar)
     IF multiply = "" THEN multiply = 1
     hx(hxx) = mid(hexVar,hxx,1)
     hxx_var = (get_hxno(hx(hxx)) * multiply) + hxx_var
     multiply = (multiply * 16)
     NEXT
     hexVar = hxx_var
     HexConv = hexVar
     END IF
     End Function
     
     Private Function get_hxno(ghx)
     If ghx = "A" Then
     ghx = 10
     ElseIf ghx = "B" Then
     ghx = 11
     ElseIf ghx = "C" Then
     ghx = 12
     ElseIf ghx = "D" Then
     ghx = 13
     ElseIf ghx = "E" Then
     ghx = 14
     ElseIf ghx = "F" Then
     ghx = 15
     End If
     get_hxno = ghx
     End Function
     
     

randomize
num = int(7999*rnd+2000) '计数器的值
num2 = EncryptString(num)
session("CheckCode")=num

%>


<%
Dim Image
Dim Width, Height
Dim num
Dim digtal
Dim Length
Dim sort
Length = 4 '自定计数器长度

Redim sort( Length )

num=cint(DeCryptString(num2))
digital = ""
For I = 1 To Length -Len( num ) '补0
    digital = digital & "0"
Next
For I = 1 To Len( num )
    digital = digital & Mid( num, I, 1 )
Next
For I = 1 To Len( digital )
    sort(I) = Mid( digital, I, 1 )
Next
Width = 8 * Len( digital )   '图像的宽度
Height = 10  '图像的高度,在本例中为固定值


Response.ContentType="image/x-xbitmap"

hc=chr(13) & chr(10)

Image = "#define counter_width " & Width & hc
Image = Image & "#define counter_height " & Height & hc
Image = Image & "static unsigned char counter_bits[]={" & hc

For I = 1 To Height
    For J = 1 To Length
        Image = Image & a(sort(J),I) & ","
    Next
Next

Image = Left( Image, Len( Image ) - 1 ) '去掉最后一个逗号
Image = Image & "};" & hc
%>
<%
Response.Write Image

%>
搜索更多相关主题的帖子: 验证 运行 
2010-08-16 15:37
gupiao175
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:40
帖 子:1787
专家分:7527
注 册:2007-6-27
得分:20 
程序代码:
<%
Option Explicit        ' 显示声明
Class Com_GifCode_Class
    Public Noisy, Count, Width, Height, Angle, Offset, Border
    Private Graph(), Margin(3)
    Private Sub Class_Initialize()
        Randomize
        Noisy    = 4    ' 干扰点出现的概率
        Count    = 6    ' 字符数量
        Width    = 100    ' 图片宽度
        Height    = 25    ' 图片高度
        Angle    = 1    ' 角度随机变化量
        Offset    = 10    ' 偏移随机变化量
        Border = 5    ' 边框大小
    End Sub
    Public Function Create()
        Const cCharSet = "123456789"
        Dim i, x, y
        Dim vValidCode : vValidCode = ""
        Dim vIndex
        ReDim Graph(Width-1, Height-1)
        For i = 0 To Count - 1
            vIndex = Int(Rnd * Len(cCharSet))
            vValidCode = vValidCode + Mid(cCharSet, vIndex+1 , 1)
            SetDraw vIndex, i
        Next
        Create = vValidCode
    End Function
    Sub SetDot(pX, pY)
        If pX * (Width-pX-1) >= 0 And pY * (Height-pY-1) >= 0 Then
            Graph(pX, pY) = 1
        End If
    End Sub
    Public Sub SetDraw(pIndex, pNumber)
        ' 字符数据
        Dim DotData(8)
        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)
        Dim vExtent : 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
        Dim vStartX, vEndX, vStartY, vEndY
        Dim vWidth, vHeight, vDX, vDY, vDeltaT
        Dim vAngle, 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)
        Dim i, j
        For i = 1 To UBound(DotData(pIndex), 1)/2
            If DotData(pIndex)(2*i-2) <> 0 And DotData(pIndex)(2*i) <> 0 Then
                ' 终点坐标
                vEndX = (DotData(pIndex)(2*i)-1) * vWidth / 100
                vEndY = (DotData(pIndex)(2*i+1)-1) * vHeight / 100
                ' 横向差距
                vDX = vEndX - vStartX
                ' 纵向差距
                vDY = vEndY - vStartY
                ' 倾斜角度
                If vDX = 0 Then
                    vAngle = Sgn(vDY) * 3.14/2
                Else
                    vAngle = Atn(vDY / vDX)
                End If
                ' 两坐标距离
                If Sin(vAngle) = 0 Then
                    vLength = vDX
                Else
                    vLength = vDY / Sin(vAngle)
                End If
                ' 随机转动角度
                vAngle = vAngle + (Rnd - 0.5) * 2 * Angle * 3.14 * 2 / 100
                vDX = Int(Cos(vAngle) * vLength)
                vDY = Int(Sin(vAngle) * vLength)
                If Abs(vDX) > Abs(vDY) Then vDeltaT = Abs(vDX) Else vDeltaT = Abs(vDY)
                For j = 1 To vDeltaT
                    SetDot Margin(0) + vStartX + j * vDX / vDeltaT, Margin(2) + vStartY + j * vDY / vDeltaT
                Next
                vStartX = vStartX + vDX
                vStartY = vStartY + vDY
            End If
        Next
    End Sub
    Public Sub Output()
        Response.Expires = -9999 
        Response.AddHeader "pragma", "no-cache"
        Response.AddHeader "cache-ctrol", "no-cache"
        Response.ContentType = "image/gif"
        ' 文件类型
        Response.BinaryWrite ChrB(Asc("G")) & ChrB(Asc("I")) & ChrB(Asc("F"))
        ' 版本信息
        Response.BinaryWrite ChrB(Asc("8")) & ChrB(Asc("9")) & ChrB(Asc("a"))
        ' 逻辑屏幕宽度
        Response.BinaryWrite ChrB(Width Mod 256) & ChrB((Width \ 256) Mod 256)
        ' 逻辑屏幕高度
        Response.BinaryWrite ChrB(Height Mod 256) & ChrB((Height \ 256) Mod 256)
        Response.BinaryWrite ChrB(128) & ChrB(0) & ChrB(0)
        ' 全局颜色列表背景颜色
        Response.BinaryWrite ChrB(0) & ChrB(0) & ChrB(0)
        ' 文字颜色
        Response.BinaryWrite ChrB(200) & ChrB(85) & ChrB(255)
        ' 图象标识符
        Response.BinaryWrite ChrB(Asc(","))
        Response.BinaryWrite ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0)
        ' 图象宽度
        Response.BinaryWrite ChrB(Width Mod 256) & ChrB((Width \ 256) Mod 256)
        ' 图象高度
        Response.BinaryWrite ChrB(Height Mod 256) & ChrB((Height \ 256) Mod 256)
        Response.BinaryWrite ChrB(0) & ChrB(7) & ChrB(255)
        Dim x, y, i : i = 0
        For y = 0 To Height - 1
            For x = 0 To Width - 1
                If Rnd < Noisy / 100 Then
                    Response.BinaryWrite ChrB(1-Graph(x, y))
                Else
                    If x * (x-Width) = 0 Or y * (y-Height) = 0 Then
                        Response.BinaryWrite ChrB(Graph(x, y))
                    Else
                        If Graph(x-1, y) = 1 Or Graph(x, y) Or Graph(x, y-1) = 1 Then
                            Response.BinaryWrite ChrB(1)
                        Else
                            Response.BinaryWrite ChrB(0)
                        End If
                    End If
                End If
                If (y * Width + x + 1) Mod 126 = 0 Then
                    Response.BinaryWrite ChrB(128)
                    i = i + 1
                End If
                If (y * Width + x + i + 1) Mod 255 = 0 Then
                    If (Width*Height - y * Width - x - 1) > 255 Then
                        Response.BinaryWrite ChrB(255)
                    Else
                        Response.BinaryWrite ChrB(Width * Height Mod 255)
                    End If
                End If
            Next
        Next
        Response.BinaryWrite ChrB(128) & ChrB(0) & ChrB(129) & ChrB(0) & ChrB(59)
    End Sub
End Class
'刷新
Response.expires=-1 
Response.AddHeader"pragma","no-cache" 
Response.AddHeader"cache-control","no-store" 
    Dim mCode
    Set mCode = New Com_GifCode_Class
    Session("GetCode") = mCode.Create()    ' 将验证码存到Session中,可以放到hidden里和输入进行比较!
    mCode.Output()    ' 输出数据
    Set mCode = Nothing
%>

没看懂楼主发的,这里是一个能用的ASP图片验证!已经测试过的!

Q:1428196631,百度:开发地 即可找到我,有事请留言!
2010-08-16 17:50
nbsyf
Rank: 1
等 级:新手上路
帖 子:382
专家分:0
注 册:2006-7-31
得分:0 
谢谢!再请教您这里是6位数的验证码,如何把它改成四位数的验证码。再把它改为原程序中的checkcode.asp内容能行吗?可能会出错吗?
2010-08-17 06:12
gupiao175
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:40
帖 子:1787
专家分:7527
注 册:2007-6-27
得分:0 
Private Sub Class_Initialize()
        Randomize
        Noisy    = 4    ' 干扰点出现的概率
        Count    = 6    ' 字符数量
        Width    = 100    ' 图片宽度
        Height    = 25    ' 图片高度
        Angle    = 1    ' 角度随机变化量
        Offset    = 10    ' 偏移随机变化量
        Border = 5    ' 边框大小
    End Sub
看清楚这段没有,知道哪里改了吗。

Q:1428196631,百度:开发地 即可找到我,有事请留言!
2010-08-17 17:04
gupiao175
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:40
帖 子:1787
专家分:7527
注 册:2007-6-27
得分:0 
你把文件名改成checkcode.asp即可,你想怎么改都行,只要和调用的地方一样即可!
例如把下面的代码保存成HTML文件,当然前提必须在IIS或能运行ASP代码的平台里!
<form method="post" action="from.asp">
<input name="Form_Code" type="text" /><input name="Submit1" type="submit" value="提交" /><SCRIPT language=javascript> document.write("<img src=checkcode.asp align=absmiddle id=Image1 onclick=Image1.src='checkcode.asp?'+Math.random(); alt=看不清楚可点击刷新/>");</SCRIPT>
</form>
前一个checkcode.asp是载入验证图片代码,后一个checkcode.asp是每点一下就换一个验证码!

Q:1428196631,百度:开发地 即可找到我,有事请留言!
2010-08-17 17:09
gupiao175
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:40
帖 子:1787
专家分:7527
注 册:2007-6-27
得分:0 
Response.AddHeader"cache-control","no-store"
    Dim mCode
    Set mCode = New Com_GifCode_Class
    Session("GetCode") = mCode.Create()    ' 将验证码存到Session中,可以放到hidden里和输入进行比较!
    mCode.Output()    ' 输出数据
    Set mCode = Nothing
红色部分是代码产生的验证码!可以在任何一个ASP页面使用,比较完成后,记得清空!
比如:
<form method="post" action="from.asp">
<input name="Form_Code" type="text" /><input name="Submit1" type="submit" value="提交" /><SCRIPT language=javascript> document.write("<img src=checkcode.asp align=absmiddle id=Image1 onclick=Image1.src='checkcode.asp?'+Math.random(); alt=看不清楚可点击刷新/>");</SCRIPT>
</form>
在from.asp里可以这样比较
<%
  dim code1=request("Form_code")'这是客户输入的验证码!
  dim code2=Session("GetCode")'这个就是上面系统自动生成的代码!
if code1=code2 then
 严重通过
else
返回重新验证
end if
%>
这是比较老的比较方法,真正这个比较可以放到HTML里无刷新验证,这里我就不讨论了。

Q:1428196631,百度:开发地 即可找到我,有事请留言!
2010-08-17 17:14



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-315861-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.134056 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved