新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论高级C/C++编程、代码重构(Refactoring)、极限编程(XP)、泛型编程等话题
    [返回] 计算机科学论坛计算机技术与应用『 C/C++编程思想 』 → [求助] 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 4554 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: [求助] 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     hysb666 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:4
      积分:61
      门派:XML.ORG.CN
      注册:2010/7/7

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给hysb666发送一个短消息 把hysb666加入好友 查看hysb666的个人资料 搜索hysb666在『 C/C++编程思想 』的所有贴子 引用回复这个贴子 回复这个贴子 查看hysb666的博客楼主
    发贴心情 [求助]

    各位大哥,我有个留言版,最近老是被机器人恶意发帖,所以想做个验证码。现在验证码是做好了,但不知道如何判断输入的验证码是否正确,现在随便输入什么都能进去。我是菜鸟,请各位大哥写个代码,还有这个代码应该放在哪里?拜托了。下面是生成验证码的文件:checkGIF.asp
    <%
    Option Explicit ' 显示声明

    Class Com_GifCode_Class

    Public Noisy, Count, Width, Height, Angle, Offset, Border

    Private Graph(), Margin(3)

    Private Sub Class_Initialize()
    Randomize
    Noisy = 6 ' 干扰点出现的概率
    Count = 4 ' 字符数量
    Width = 80 ' 图片宽度
    Height = 20 ' 图片高度
    Angle = 2 ' 角度随机变化量
    Offset = 20 ' 偏移随机变化量
    Border = 1 ' 边框大小
    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(255) & ChrB(255) & ChrB(255)

    Response.BinaryWrite ChrB(0) & 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

    Dim mCode
    Set mCode = New Com_GifCode_Class
    Session("GetCode") = mCode.Create()
    mCode.Output()
    Set mCode = Nothing
    %>

    下面是放在需要输入验证码页面的代码:
    <input name="CheckCode" type="text" class="InputTxtLogin" id="CheckCode" onMouseOver="this.style.background='#ffffff';" onMouseOut="this.style.background='#f3f3f3'" size="4" maxlength="4"><img src="checkGIF.asp">

    第三是需要判断是否输入正确,怎么写?放在哪里?谢谢啊


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2010/7/8 8:12:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 C/C++编程思想 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/11/22 15:21:58

    本主题贴数1,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    250.000ms