以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [分享][求助] 关于官方验证码的疑问与建议  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=150701)

--  作者:菜鸟王中王
--  发布时间:2020/6/5 10:46:00
--  [分享][求助] 关于官方验证码的疑问与建议
按照官方的代码调试通过验证码,用的以下代码:

mark验证码

 

Select Case e.Path
    Case "login.htm"
        Dim wb As New weui
        wb.AddForm("","form1","login.htm")
        With wb.AddInputGroup("form1","ipg1","登录")
            If e.PostValues.ContainsKey("isj") AndAlso e.PostValues.ContainsKey("imm")  Then \'判断是否是验证失败后的重新登录
                wb.AddTopTips("","toptip1","用户名或密码错误!").msec = 2000 \'如果用户通过登录按钮访问,则给用户一个2秒的提示.
            End If
            With .AddInputCell("ic1")  \'通过InputCell增加输入框(1表示突出显示,2表示红色警示图标)
                .AddLabel("lsj","手机",0)  \'增加标签(0显示在左边)
                .AddInput("isj","text",1).PlaceHolder= "请输入手机号"  \'增加输入框(0靠左显示,1居中显示,2靠右显示)
            End With
            With .AddInputCell("ic2")
                .AddLabel("lmm","密码",0)
                .AddInput("imm","password",1).PlaceHolder= "请输入密码"
            End With
            With .AddInputCell("ic5") \'通过InputCell增加输入框
                .AddLabel("lyzm","验证码",0) \'增加标签,0显示在左边
                .AddInput("yzm","text",1) \'增加输入框,1表示显示在中间
                .AddImage("pim","/getVimg.htm",2).Attribute="onclick=""this.src = \'getVimg.htm?rand=\' + Math.random() """ \'增加一个图片,2比表示显示在右边
            End With
            \'End With
            .AddSwitch("jizhumima","记住密码")
            With wb.AddButtonGroup("form1","btg1",True)
                .Add("btn1", "登录", "","submit") \'"/index.htm")
            End With
            With wb.AddButtonGroup("form1","btg2", False)
                .Add("btn2", "免费注册","","/register.htm").Kind = 1
                .Add("btn3", "忘记密码","","/getback.htm").Kind = 1
            End With
        End With
        e.WriteString(wb.Build) \'生成网页
    Case "getVimg.htm"
        Dim bmp As new bitmap(70, 40)
        Dim g As Graphics = Graphics.FromImage(bmp)
        Dim Val1 As Double = Rand.Next(10000)
        Dim fnt As New Font("宋体",16)
        Dim msg As String = format(val1, "0000")
        g.DrawString(msg,fnt,Brushes.Red,10,10)
        e.AppendCookie("yanzhengma", msg)  \'校对这个cookie
        \'bmp.Save(ProjectPath & "Images\\temp.jpg")
        \'bmp.dispose
        \'e.WriteFile(ProjectPath & "Images\\temp.jpg")
        Dim ms As new IO.MemoryStream()
        bmp.Save(ms, ImageFormat.png)
        Dim buffer = ms.ToArray
        e.Response.ContentType = "image/Png"
        Dim output = e.response.OutputStream
        output.Write(buffer,0,buffer.Length)
        output.Close()
End Select



**************************

建议1:     .AddInput("yzm","text",1) \'增加输入框,1表示显示在中间,把 text 改成  number 这样严谨一点,即:     .AddInput("yzm","number",1) \'增加输入框,1表示显示在中间

问题1:    如果多个浏览器同时访问会不会出问题?


--  作者:有点蓝
--  发布时间:2020/6/5 10:55:00
--  
1、例子而已,根据自己需要改。比如别人有可能使用的是字符+数字的验证码
2、不会有问题
[此贴子已经被作者于2020/6/5 10:55:35编辑过]