login.ascx
由于在页面上很频繁使用登陆,把它做成一个控件是很有必要的,下面就是我写的一个简单的登陆控件,大家可以根据的需要完善一下。
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Oledb" %>
Sub Page_Load(sender As Object,e As EventArgs)
session("Accessed")=false
If session("UserName")="" And Not IsPassLogin() then
lblLogin.visible=true
lblMessage.visible=false
IsPassLogin()
else
lblMessage.Text=ShowPrompt(True)
lblMessage.visible=true
lblLogin.visible=false
End If
End Sub
'用户登陆验证
Public Function IsPassLogin() As Boolean
Dim MyConnection As OledbConnection
Dim strConnection As String="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("DataBase/popmarry.mdb")
MyConnection=New OledbConnection(strConnection)
Dim sqlCommand="SELECT * FROM InMember WHERE MemberID='" & UserID & "'" & " AND Pwd='" & UserPassword & "'"
Dim MyAdapter As New OleDbDataAdapter(sqlCommand,MyConnection)
Dim ds As DataSet=New DataSet()
MyAdapter.Fill(ds,"InMember")
Dim dt As DataTable=ds.Tables("InMember")
If dt.Rows.Count>0 Then
Session("UserName")=UserID
Return(true)
Else
Return(false)
End If
End Function
'显示登陆信息
Public Function ShowPrompt(bolInfo As Boolean) As String
If bolInfo Then
Dim strWelcome As String
strWelcome="
| 欢迎您," & Session("UserName") & " | |||
| "
strWelcome &="
strWelcome &="
|
'返回成功登陆信息
Return(strWelcome)
Else
Dim strError As String
strError="
| 登录失败: 1.用户名或密码错误 2.此帐号被锁定 3.未注册 |
'返回登陆失败信息
Return(strError)
End If
End Function
Public Property UserID As String
Get
UserID=txtUserID.Text
End Get
Set
txtUserID.Text=value
End Set
End Property
'定义UserPassword的属性
Public Property UserPassword As String
Get
UserPassword=txtUserPassword.Text
End Get
Set
txtUserPassword.Text=value
End Set
End property
|
||||||||||

