水平有限,采用特笨的办法实现,分享给初学的狐友:
Select Case e.Path
Case "logon.htm",""
Functions.Execute("logon",e)
Case "logon_yz.htm"
Functions.Execute("logon_yz",e)
Case Else
Dim usernam As String=""
Dim Password As String=""
If e.Cookies.ContainsKey("usernam") Then
usernam= e.Cookies("usernam") '从cookie中获取用户名
Password= e.Cookies("password") '从cookie中获取用户密码
End If
If Password>"" AndAlso usernam>"" Then
Dim d2 As Date = Date.now
If e.Cookies.ContainsKey("dlsj") Then
Dim d1 As Date = e.Cookies("dlsj") '获取上次登陆时间
Dim t As TimeSpan = d2 - d1
If t.TotalMinutes>150 Then '如果距上次登陆时间超过150分钟则图片验证
Functions.Execute("logon_yz",e)
Return
End If
Else '如果新打开浏览器则图片验证
Functions.Execute("logon_yz",e)
Return
End If
e.AppendCookie("dlsj",d2) '保存登录时间以备用
Select Case e.Path
Case "xs_xzml.htm"
Functions.Execute("xs_xzml",e)
Case "xs_list.htm"
Functions.Execute("xs_List",e) '分页显示
End Select
Else '如果密码登陆超过3天清空了,则重新登陆
Functions.Execute("logon",e)
End If
End Select
===============================================================================================================
Functions.Execute("logon_yz",e)内容如下:
Dim e As RequestEventArgs = args(0)
Dim cmd As New SQLCommand
cmd.ConnectionName = vars("_conn")
Dim dt As DataTable
Dim dr As DataRow
Dim yhdr As DataRow
Dim drs As List(Of DataRow)
Dim dlyz As String ="" '记录选择的图名
Dim dlyzj As Integer=1 '记录选择图的个数,共需选择3个图
Dim i As Integer=1
Dim usernam As String=""
If e.Cookies.ContainsKey("usernam") Then
usernam= e.Cookies("usernam") '从cookie中获取用户名
End If
yhdr=DataTables("用户表").sqlfind("用户名='" & usernam & "'") '用户表中含图名1 图名2 图名3 三列放三个需验证的图
If yhdr IsNot Nothing Then
cmd.CommandText = "select * fro m {登陆验证图} where 1=1" '该表有图名 随机数 排序三列
dt = cmd.ExecuteReader()
Dim wb As New WeUI
If e.getValues.ContainsKey("xz") Then '如果选择了图
dlyz=e.getValues("xz") '等于选择的图名
dlyzj=e.Cookies("dlyzj")+1 '记录选择图的个数
End If
For Each dr In dt.DataRows
dr("随机数")= Rand.Next(1000,9990)
Next
If dlyzj=1 Then
dt.ReplaceFor("随机数",1, "图名='" & yhdr("图名1") & "'") '将用户预先设定的第一个图的随机数改为1,以保证出现在头21个图中供选择
ElseIf dlyzj=2 Then '第一个图选完
If yhdr("图名1")<>e.getValues("xz") Then '如选择的第一个图不符,则退出重新登陆
wb.AddForm("","form1","logon_yz.htm")
With wb.AddButtonGroup("form1","btg6", False)
.Add("btn9", "OK","button","logon.htm?tctc='tctc'") '退出重新密码登陆
End With
e.WriteString(wb.Build)
Return ""
End If
dt.ReplaceFor("随机数",1, "图名='" & yhdr("图名2") & "'") '将用户预先设定的第二个图的随机数改为1,以保证出现在头21个图中供选择
ElseIf dlyzj=3 Then '第二个图选完
If yhdr("图名2")<>e.getValues("xz") Then '如选择的第二个图不符,则退出重新登陆
wb.AddForm("","form1","logon_yz.htm")
With wb.AddButtonGroup("form1","btg6", False)
.Add("btn9", "OK","button","logon.htm?tctc='tctc'") '退出重新密码登陆
End With
e.WriteString(wb.Build)
Return ""
End If
dt.ReplaceFor("随机数",1, "图名='" & yhdr("图名3") & "'") '将用户预先设定的第三个图的随机数改为1,以保证出现在头21个图中供选择
Else '第三个图选完
If yhdr("图名3")<>e.getValues("xz") Then '如选择的第三个图不符,则退出重新登陆
wb.AddForm("","form1","logon_yz.htm")
With wb.AddButtonGroup("form1","btg6", False)
.Add("btn9", "OK","button","logon.htm?tctc='tctc'") '退出重新密码登陆
End With
e.WriteString(wb.Build)
Return ""
End If
Dim d2 As Date = Date.now
e.AppendCookie("dlsj",d2) '保存登录时间以备用
Functions.Execute("logon",e)
Return ""
End If
wb.AppendCookie("dlyzj",dlyzj)
drs = dt.Select("随机数<9999","随机数") '按随机数排列下
For Each dr In drs
dr("随机数")= Rand.Next(1000,9990)
dr("排序")=i
i=i+1
Next
drs = dt.Select("排序<22","随机数") '取前21个图
wb.AddPageTitle("","pageheader","","")
With wb.AddGrid("","g1")
For Each dr In drs
.Add("c1","","./images/dlyz/" & dr("图名") & ".jpg","logon_yz.htm?xz=" & dr("图名")) 'xz=选择的图名
Next
End With
e.WriteString(wb.Build)
End If