473,569 Members | 3,043 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Forms Login/Logout

We have our windows forms login set up and working good, well it works at
least, just now we need a logout button, so when you click on it, the user
will be logged out of the authentication, how would we do this? this is how
we are doing the login form

==[web config changes]=====
<authenticati on mode="Forms">

<forms loginUrl="/WebClient/SecurePages/logon.aspx" name="RSMNEmail "
timeout="20" path="/"></forms>

</authentication>

<!-- AUTHORIZATION

This section sets the authorization policies of the application. You can
allow or deny access

to application resources by user or role. Wildcards: "*" mean everyone, "?"
means anonymous

(unauthenticate d) users.

-->

<authorizatio n>

<deny users="?" />

<allow users="*" />
<!-- Allow all users -->

<!-- <allow users="[comma separated list of users]"

roles="[comma separated list of roles]"/>

<deny users="[comma separated list of users]"

roles="[comma separated list of roles]"/>

-->

</authorization>

=[ login form script]=======

Imports System.Web.Secu rity

Imports System.Security

Public Class Logon

Inherits System.Web.UI.P age

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.

<System.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent()

End Sub

Protected WithEvents txtUserName As System.Web.UI.W ebControls.Text Box

Protected WithEvents txtPassword As System.Web.UI.W ebControls.Text Box

Protected WithEvents lblInvalid As System.Web.UI.W ebControls.Labe l

Protected WithEvents btnLogin As System.Web.UI.W ebControls.Butt on

Protected WithEvents hlnkApplyUser As System.Web.UI.W ebControls.Hype rLink

'NOTE: The following placeholder declaration is required by the Web Form
Designer.

'Do not delete or move it.

Private designerPlaceho lderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init

'CODEGEN: This method call is required by the Web Form Designer

'Do not modify it using the code editor.

InitializeCompo nent()

End Sub

#End Region
Private Sub btnLogin_Click( ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnLogin.Click

If txtUserName.Tex t <> "" And txtPassword.Tex t <> "" Then

If database.msgCon nection.State = ConnectionState .Closed Then

database.msgCon nection.Open()

End If

Dim cmdCheckUser As New SqlClient.SqlCo mmand("RSMN_Che ckPassword",
database.msgCon nection)

cmdCheckUser.Co mmandType = CommandType.Sto redProcedure

cmdCheckUser.Pa rameters.Add("@ userName", SqlDbType.VarCh ar).Value =
txtUserName.Tex t

cmdCheckUser.Pa rameters.Add("@ Password", SqlDbType.VarCh ar).Value =
txtPassword.Tex t

' check login credentials against SQL Users's database for messaging system

If DirectCast(cmdC heckUser.Execut eScalar, Boolean) = True Then

Dim loginAuthCookie As FormsAuthentica tionTicket = New
FormsAuthentica tionTicket(1, txtUserName.Tex t, DateTime.Now,
DateTime.Now.Ad dMinutes(20), False, "WebUser")

Dim encryptedTicket As String = FormsAuthentica tion.Encrypt(lo ginAuthCookie)

Dim authCookie As HttpCookie = New
HttpCookie(Form sAuthentication .FormsCookieNam e, encryptedTicket )

Response.Cookie s.Add(authCooki e)

Response.Redire ct("Inbox.aspx" , True)

Else

lblInvalid.Visi ble = True

End If

If database.msgCon nection.State = ConnectionState .Open Then

database.msgCon nection.Close()

End If

Else

lblInvalid.Visi ble = True

End If

End Sub

End Class

now on the main page after they logon there is a button that says logoff,
when they click on it we want them loged out of the system and redirected to
the logon page, how to do this? thanks
Nov 18 '05 #1
2 1641
Hi Brian,

FormsAuthentica tion.SignOut() is what you need.
It deletes the authentication cookie.

HTH,
Stefano Mostarda MCP
Rome Italy;

Brian Henry wrote:
We have our windows forms login set up and working good, well it works at
least, just now we need a logout button, so when you click on it, the user
will be logged out of the authentication, how would we do this? this is how
we are doing the login form

==[web config changes]=====
<authenticati on mode="Forms">

<forms loginUrl="/WebClient/SecurePages/logon.aspx" name="RSMNEmail "
timeout="20" path="/"></forms>

</authentication>

<!-- AUTHORIZATION

This section sets the authorization policies of the application. You can
allow or deny access

to application resources by user or role. Wildcards: "*" mean everyone, "?"
means anonymous

(unauthenticate d) users.

-->

<authorizatio n>

<deny users="?" />

<allow users="*" />
<!-- Allow all users -->

<!-- <allow users="[comma separated list of users]"

roles="[comma separated list of roles]"/>

<deny users="[comma separated list of users]"

roles="[comma separated list of roles]"/>

-->

</authorization>

=[ login form script]=======

Imports System.Web.Secu rity

Imports System.Security

Public Class Logon

Inherits System.Web.UI.P age

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.

<System.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent()

End Sub

Protected WithEvents txtUserName As System.Web.UI.W ebControls.Text Box

Protected WithEvents txtPassword As System.Web.UI.W ebControls.Text Box

Protected WithEvents lblInvalid As System.Web.UI.W ebControls.Labe l

Protected WithEvents btnLogin As System.Web.UI.W ebControls.Butt on

Protected WithEvents hlnkApplyUser As System.Web.UI.W ebControls.Hype rLink

'NOTE: The following placeholder declaration is required by the Web Form
Designer.

'Do not delete or move it.

Private designerPlaceho lderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init

'CODEGEN: This method call is required by the Web Form Designer

'Do not modify it using the code editor.

InitializeCompo nent()

End Sub

#End Region
Private Sub btnLogin_Click( ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnLogin.Click

If txtUserName.Tex t <> "" And txtPassword.Tex t <> "" Then

If database.msgCon nection.State = ConnectionState .Closed Then

database.msgCon nection.Open()

End If

Dim cmdCheckUser As New SqlClient.SqlCo mmand("RSMN_Che ckPassword",
database.msgCon nection)

cmdCheckUser.Co mmandType = CommandType.Sto redProcedure

cmdCheckUser.Pa rameters.Add("@ userName", SqlDbType.VarCh ar).Value =
txtUserName.Tex t

cmdCheckUser.Pa rameters.Add("@ Password", SqlDbType.VarCh ar).Value =
txtPassword.Tex t

' check login credentials against SQL Users's database for messaging system

If DirectCast(cmdC heckUser.Execut eScalar, Boolean) = True Then

Dim loginAuthCookie As FormsAuthentica tionTicket = New
FormsAuthentica tionTicket(1, txtUserName.Tex t, DateTime.Now,
DateTime.Now.Ad dMinutes(20), False, "WebUser")

Dim encryptedTicket As String = FormsAuthentica tion.Encrypt(lo ginAuthCookie)

Dim authCookie As HttpCookie = New
HttpCookie(Form sAuthentication .FormsCookieNam e, encryptedTicket )

Response.Cookie s.Add(authCooki e)

Response.Redire ct("Inbox.aspx" , True)

Else

lblInvalid.Visi ble = True

End If

If database.msgCon nection.State = ConnectionState .Open Then

database.msgCon nection.Close()

End If

Else

lblInvalid.Visi ble = True

End If

End Sub

End Class

now on the main page after they logon there is a button that says logoff,
when they click on it we want them loged out of the system and redirected to
the logon page, how to do this? thanks

Nov 18 '05 #2
thanks!
"Stefano Mostarda" <st************ **@fastwebnet.i t> wrote in message
news:eD******** ******@TK2MSFTN GP12.phx.gbl...
Hi Brian,

FormsAuthentica tion.SignOut() is what you need.
It deletes the authentication cookie.

HTH,
Stefano Mostarda MCP
Rome Italy;

Brian Henry wrote:
We have our windows forms login set up and working good, well it works at least, just now we need a logout button, so when you click on it, the user will be logged out of the authentication, how would we do this? this is how we are doing the login form

==[web config changes]=====
<authenticati on mode="Forms">

<forms loginUrl="/WebClient/SecurePages/logon.aspx" name="RSMNEmail "
timeout="20" path="/"></forms>

</authentication>

<!-- AUTHORIZATION

This section sets the authorization policies of the application. You can
allow or deny access

to application resources by user or role. Wildcards: "*" mean everyone, "?" means anonymous

(unauthenticate d) users.

-->

<authorizatio n>

<deny users="?" />

<allow users="*" />
<!-- Allow all users -->

<!-- <allow users="[comma separated list of users]"

roles="[comma separated list of roles]"/>

<deny users="[comma separated list of users]"

roles="[comma separated list of roles]"/>

-->

</authorization>

=[ login form script]=======

Imports System.Web.Secu rity

Imports System.Security

Public Class Logon

Inherits System.Web.UI.P age

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.

<System.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent()
End Sub

Protected WithEvents txtUserName As System.Web.UI.W ebControls.Text Box

Protected WithEvents txtPassword As System.Web.UI.W ebControls.Text Box

Protected WithEvents lblInvalid As System.Web.UI.W ebControls.Labe l

Protected WithEvents btnLogin As System.Web.UI.W ebControls.Butt on

Protected WithEvents hlnkApplyUser As System.Web.UI.W ebControls.Hype rLink
'NOTE: The following placeholder declaration is required by the Web Form
Designer.

'Do not delete or move it.

Private designerPlaceho lderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init

'CODEGEN: This method call is required by the Web Form Designer

'Do not modify it using the code editor.

InitializeCompo nent()

End Sub

#End Region
Private Sub btnLogin_Click( ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnLogin.Click

If txtUserName.Tex t <> "" And txtPassword.Tex t <> "" Then

If database.msgCon nection.State = ConnectionState .Closed Then

database.msgCon nection.Open()

End If

Dim cmdCheckUser As New SqlClient.SqlCo mmand("RSMN_Che ckPassword",
database.msgCon nection)

cmdCheckUser.Co mmandType = CommandType.Sto redProcedure

cmdCheckUser.Pa rameters.Add("@ userName", SqlDbType.VarCh ar).Value =
txtUserName.Tex t

cmdCheckUser.Pa rameters.Add("@ Password", SqlDbType.VarCh ar).Value =
txtPassword.Tex t

' check login credentials against SQL Users's database for messaging system
If DirectCast(cmdC heckUser.Execut eScalar, Boolean) = True Then

Dim loginAuthCookie As FormsAuthentica tionTicket = New
FormsAuthentica tionTicket(1, txtUserName.Tex t, DateTime.Now,
DateTime.Now.Ad dMinutes(20), False, "WebUser")

Dim encryptedTicket As String = FormsAuthentica tion.Encrypt(lo ginAuthCookie)
Dim authCookie As HttpCookie = New
HttpCookie(Form sAuthentication .FormsCookieNam e, encryptedTicket )

Response.Cookie s.Add(authCooki e)

Response.Redire ct("Inbox.aspx" , True)

Else

lblInvalid.Visi ble = True

End If

If database.msgCon nection.State = ConnectionState .Open Then

database.msgCon nection.Close()

End If

Else

lblInvalid.Visi ble = True

End If

End Sub

End Class

now on the main page after they logon there is a button that says logoff, when they click on it we want them loged out of the system and redirected to the logon page, how to do this? thanks

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1501
by: AAOMTim | last post by:
I want to automatically logout if certain conditions occur in my application. Calling Session.Abandon() does not force a logout. What can I do? -- Tim
4
1609
by: mwhite | last post by:
Hi, I'm adding a security layer to a companies intranet pages. I have created a login page, using the Asp.Net 2 login control, and am using Forms Authentication. I have set the <formstimeout attribute to 5mins, as they don't want anyone to be able to view the secure pages without logging in. It works fine when I build the project and run...
0
1945
by: ShailShin | last post by:
Hi All, Developing an VB App for Login and logout tracking. In App Form there are two buttons login and logout. When user click on login the loginName, LoginTime and LoginDate get stored in .MDB file. Same with the logout but i need that logout time should get stored in the row where login details get stored and "LoginTime - LogoutTime =...
2
4938
by: Dan | last post by:
Hi, I use the logon control for logging into the application. When logging and checking the option "remember me next time" and then closing the browser without to press any logout button which logout the user, the next time i start the browser and go to the application, i don't need to login. That's ok. My questions are:
1
5710
by: gnewsgroup | last post by:
I am using forms authentication for a web application. Like many other member web application, my web application prints out Welcome! John Doe (Logout) on the top right corner of each protected page. But, pages can still be visited by following the links in the web application after a session has timed out, data can still be retrieved
1
3317
by: Kandiman | last post by:
Hiya, i made a asp page, and one of my divs (as a include) is as below. the problem is if the main page is resubmitted, i get logged out again?... heres the code.. i think its on the value=true for the hidden textbox on the logout sub.. but how do i get round this? can i not change the value onclick? <div id=Rightbody> <!--<form...
1
3283
by: Adrock952 | last post by:
I have a link on my site which obviously says "Login" where users log in. I would like that link to be changed to "Logout" when the user has successfully logged in and the session has been created and when the user logs out, i would like the link changed back to "Login" without having to refresh the page. here is my login page <?php if...
5
6775
by: =?Utf-8?B?Y2hlY2tyYWlzZXJAY29tbXVuaXR5Lm5vc3BhbQ== | last post by:
I have a site which I secure with forms authentication. When the user's sign on and hit one of the secure pages, I have this line in my code to ensure that the browser does not cache the page; and someone cannot navigate back to an cached image of the page in theory after the user has signed off. ...
10
4800
by: DavidPr | last post by:
When I logout as one user and log in under a different user, it opens with the last user's information. User 1 - Unsername: Davey Jones User 2 - Unsername: David Smith I log out from Davey Jones, then login as David Smith the Welcome message below will show "Welcome Davey". And it will be Davey's information that is accessible - not David...
0
7619
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7930
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7681
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5228
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3662
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.