Hi guys i have created a simple login sample using custom login codes. Here i have use session to created a session of the users. I have also taken the database to access username and password.
The code behind login button is:
Sub SubmitBtn_Click(Sender As Object, E As EventArgs)
Dim DBConn as OleDbConnection
Dim DBCommand As OleDbDataAdapter
Dim DSLogin as New DataSet
DBConn = New OleDbConnection("PROVIDER=" _
& "Microsoft.Jet.OLEDB.4.0;" _
& "DATA SOURCE=" _
& Server.MapPath("LogIn.mdb;"))
DBCommand = New OleDbDataAdapter _
("Select UserID from " _
& "Users Where " _
& "UserName = '" & txtUserName.Text _
& "' and Password = '" & txtPassword.Text _
& "'", DBConn)
DBCommand.Fill(DSLogin, _
"UserInfo")
If DSLogin.Tables("UserInfo"). _
Rows.Count = 0 Then
lblMessage.Text = "The user name and password " _
& "were not found. Please try again."
Else
Session("UserID") = DSLogin.Tables("UserInfo"). _
Rows(0).Item("UserID")
Session("UserName") = txtUserName.Text
Response.Redirect("./welcome.aspx")
End If
The Code for logout button will be:
Session.Removeall()
Response.Redirect("login.aspx")
There are various ways available to do login but this is the simplest form of it.
Search
Sunday, February 28, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment