hi , i have made a login system which saves and chekcs the data from sql server. My login is working perfectly fine. now i just want to know how to logout from an application.
can any 1 help. what functionality can i add to the logout. so that application remain oepn but it shows me the login form again

Assume two different form one for login and other for only Authorized entry..

So after login user navigated to Authorized form. Now...

You can place a Loguot Button/Menu so that user will click for logout.

Now when logout button pressed Just clear all Variables value which you used for storing the session, and then hide this form and navigate to the login form again.......

Simple....

i am a bit confused about session here. how can i store the session information. because right now what i am doing is . i am matching the login information and user type from sql and if information matches than it takes to the next form. can u please clearify the sessions here and how to use them.thnx

Session variables are the stored data about the user.

Like in authorized form u may take variables like

Public Username As String
Public Usertype As String
Public IsAdmin as Boolean

Now when user login all the variables are initialized and the user will navigated to the next form....

Now when he/she press logout button. Just clear all login info from those variables and hide that form and show the login form again....

hi .bcz i am not familiar with sessions.here is my login code could you tell me where to use the above datatype and use them as sessions..thnx plz help i am stuck in this problem for 8 hours now

Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
If txtUsername.Text = "" Or txtPassword.Text = "" Or cmbUserType.Text = "" Then
MsgBox("Please fill in All required fields")
Else
Dim conn As New SqlClient.SqlConnection
Dim command As New SqlClient.SqlCommand
Dim Adaptor As New SqlClient.SqlDataAdapter
Dim dataset As New DataSet

conn.ConnectionString = ("Data Source=SAAD-PC\SQLEXPRESS;Initial Catalog=photoshoot;Integrated Security=True")
command.CommandText = "SELECT *FROM [staff] WHERE UserName='" & txtUserName.Text & "' AND Password='" & txtPassword.Text & "' AND UserType='" & cmbUserType.Text & "'"
conn.Open()
command.Connection = conn
Adaptor.SelectCommand = command
Adaptor.Fill(dataset, "0")
Dim count = dataset.Tables(0).Rows.Count
If count > 0 Then
Main_Menu.Show()
Me.Hide()
Else
MsgBox("incorrect login details", MsgBoxStyle.Critical)
End If
End If

If cmbUserType.Text = "Administrator" Then
Main_Menu.BtnReg.Show()
Else
Main_Menu.BtnReg.Hide()


End If

Just Init Session Here

If cmbUserType.Text = "Administrator" Then
Main_Menu.BtnReg.Show()
MainFrm.Username =txtUserName.Text
MainFrm.Usertype="Administrator"
MainFrm.IsAdmin =True

Else
Main_Menu.BtnReg.Hide()
MainFrm.Username =txtUserName.Text
MainFrm.Usertype="NormalUser"
MainFrm.IsAdmin =False

End If

Assume MainFrm is the authorized form..

hi .the above coding which u have given my program is giving me error on

MainFrm.Username =txtUserName.Text
MainFrm.Usertype="Administrator"

i have replaced Mainfrm with main_menu but the .username...what is it.
i have placed your given code in the login_click event ...but not working.

main_menu is the next form after login which has only 3 button..register employee, booking . search..could u clearify..
.username=textusername.text

First declare

Public Username As String
Public Usertype As String
Public IsAdmin as Boolean

these 3 variables in main_menu

Sorry friend,. but i think u are unable to understand the question.
if i put the above 3 variables in main_menu which is the 2nd screen after login. The error which i am getting is. username,user type is not member of photoshoot.login

if i put the 3 variables in login screen which is the 1st screen of my project than there no no error.but how to use the logout fucntion.or you want me to put this coding

If cmbUserType.Text = "Administrator" Then
Main_Menu.btnReg.Show()
Me.Username = txtUserName.Text
Me.Usertype = "Administrator"
Me.IsAdmin = True

Else
Main_Menu.btnReg.Hide()
Me.Username = txtUserName.Text
Me.Usertype = "NormalUser"
Me.IsAdmin = False

into logout button which is placed on main_menu..thnx

hi Could you also tell me if i can display the user type of a person on the main_menu form..Eg if employee logs in ..on the main menu it should say logged in as Employee. and when i logout it should take me back to the login screen and clears the employee status.thnx u being very help full

Your code....

If cmbUserType.Text = "Administrator" Then
Main_Menu.btnReg.Show()
Me.Username = txtUserName.Text
Me.Usertype = "Administrator"
Me.IsAdmin = True

Else
Main_Menu.btnReg.Hide()
Me.Username = txtUserName.Text
Me.Usertype = "NormalUser"
Me.IsAdmin = False

________________

Modified Code

If cmbUserType.Text = "Administrator" Then
Main_Menu.btnReg.Show()
Main_Menu.Username = txtUserName.Text
Main_Menu.Usertype = "Administrator"
Main_Menu.IsAdmin = True

Else
Main_Menu.btnReg.Hide()
Main_Menu.Username = txtUserName.Text
Main_Menu.Usertype = "NormalUser"
Main_Menu.IsAdmin = False

Why you are using Me when you declare all variables into Main_Menu ?

Now check this again....



Now in the Main_Menu form take some labels and display the User Data.

Like Label1.Text=Username
Label2.Text=UserType

Etc...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.