以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  页面身份验证问题  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=147140)

--  作者:aidimeng
--  发布时间:2020/3/10 16:46:00
--  页面身份验证问题

Dim Verified As Boolean \'用于标记用户是否通过了身份验证
Dim UserName As String = e.Cookies("username") \'从cookie中获取用户名
Dim Password As String = e.Cookies("password") \'从cookie中获取用户密码
If e.Path = "logon.htm" \'如果是通过登录页面访问,从PostValues即可中提取用户名和密码
    If e.PostValues.ContainsKey("username") AndAlso e.PostValues.ContainsKey("password")  Then
        UserName = e.PostValues("username")
        Password = e.PostValues("password")
    End If
End If
\'MessageBox.Show("name=\'"& UserName  &"\' AndAlso password=\'"& Password  &"\' ")

Dim ddr As DataRow= DataTables("user").SQLFind("name=\'"& UserName  &"\' AndAlso password=\'"& Password  &"\' ")
 If ddr IsNot Nothing
 
    Verified  = True
 
End If
If Verified AndAlso e.Path = "logon.htm"  Then \'如果用户访问的是登录页,且身份验证成功
    wb.AppendCookie("username",ddr("name")) \'将用户名和密码写入cookie
    wb.AppendCookie("password",ddr("password"))
    wb.InsertHTML("<meta http-equiv=\'Refresh\' c>") \'直接跳转到首页
    e.WriteString(wb.Build) \'生成网页
    Return \'必须的
\'ElseIf Verified = False AndAlso e.Path <> "logon.htm" Then \'如果用户身份验证失败,且访问的不是登录页面
    \'wb.InsertHTML("<meta http-equiv=\'Refresh\' c>") \'那么直接跳转到登录页面
    \'e.WriteString(wb.Build) \'生成网页
    \'Return \'必须的
End If

Select Case e.Path
 Case "logon.htm" \'登录页面
 
        wb.AddPageTitle("","pageheader","销售系统"," 有限公司")
        If e.PostValues.ContainsKey("username") AndAlso e.PostValues.ContainsKey("password")  Then \'判断是否是验证失败后的重新登录
            wb.AddTopTips("","toptip1","用户名或密码错误!").msec = 2000 \'如果用户通过登录按钮访问,则给用户一个2秒的提示.
        End If
        wb.AddForm("","form1","logon.htm")
        With wb.AddInputGroup("form1","ipg1")
            .AddInput("username","户名","text")
            .AddInput("password","密码","password")
        End With
        With wb.AddButtonGroup("form1","btg1",True)
            .Add("btn1", "登录", "submit")
        End With
e.WriteString(wb.Build)
end select

 

我修改了例子中的登录代码,从数据库中去验证,怎么总是验证不过去啊


--  作者:有点蓝
--  发布时间:2020/3/10 16:58:00
--  
Dim ddr As DataRow= DataTables("user").SQLFind("name=\'" & UserName  &"\' And password=\'" & Password  & "\' ")

AndAlso 是代码的用法,SQL或者表达式里使用and

--  作者:aidimeng
--  发布时间:2020/3/10 17:01:00
--  
谢谢  我一直在纠结 isnot nothing 上了
--  作者:aidimeng
--  发布时间:2020/3/10 17:23:00
--  
谢谢甜老师,如果页面很多,能否把代码存储在web目录下 用txt格式呢?
--  作者:有点蓝
--  发布时间:2020/3/10 17:32:00
--  
使用函数,如:http://www.foxtable.com/mobilehelp/topics/0025.htm