How To Create A Remember Me Cookie

Please support our ASP.NET advertiser: 50% off 6 Months Dedicated Server Hosting from 1&1!
Thread Solved

Join Date: Jun 2005
Posts: 50
Reputation: Naters_uk is an unknown quantity at this point 
Solved Threads: 0
Naters_uk Naters_uk is offline Offline
Junior Poster in Training

How To Create A Remember Me Cookie

 
0
  #1
Aug 14th, 2005
I am using aspx.vb to create a login page. I would like to create a remember me cookie using a checkbox that will help to remember user ID but will also allow it to be destroy if a different user ID wants to log in with the same computer, but i have no idea how to start. Any assistance? Thank you! :cry:
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 17
Reputation: cambia is an unknown quantity at this point 
Solved Threads: 3
cambia's Avatar
cambia cambia is offline Offline
Newbie Poster

Re: How To Create A Remember Me Cookie

 
0
  #2
Aug 19th, 2005
You might start with Forms Authentication in .NET. It automates the "remember me" cookie with the following method call.

  1. FormsAuthentication.SetAuthCookie(userName, saveLogin);
Here's a place to begin learning more:
MSDN Documentation for SetAuthCookie Method

Cheers,
- Steve
Reply With Quote Quick reply to this message  
Join Date: Jan 2010
Posts: 1
Reputation: fullget is an unknown quantity at this point 
Solved Threads: 0
fullget fullget is offline Offline
Newbie Poster
 
0
  #3
Jan 18th, 2010
here is some code you can find it use full

  1. Partial Class _Default
  2. Inherits System.Web.UI.Page
  3.  
  4. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  5. If Not IsPostBack Then
  6. 'Check if the browser support cookies
  7. If Request.Browser.Cookies Then
  8. 'Check if the cookies with name PBLOGIN exist on user's machine
  9. If Request.Cookies("PBLOGIN") IsNot Nothing Then
  10. 'Pass the user name and password to the VerifyLogin method
  11. Me.VerifyLogin(Request.Cookies("PBLOGIN")("UNAME").ToString(), Request.Cookies("PBLOGIN")("UPASS").ToString())
  12. End If
  13. End If
  14. End If
  15. End Sub
  16.  
  17. Protected Sub BtLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs)
  18. 'check if remember me checkbox is checked on login
  19. If (Me.CbRememberMe.Checked) Then
  20. 'Check if the browser support cookies
  21. If (Request.Browser.Cookies) Then
  22. 'Check if the cookie with name PBLOGIN exist on user's machine
  23. If (Request.Cookies("PBLOGIN") Is Nothing) Then
  24. 'Create a cookie with expiry of 30 days
  25. Response.Cookies("PBLOGIN").Expires = DateTime.Now.AddDays(30)
  26. 'Write username to the cookie
  27. Response.Cookies("PBLOGIN").Item("UNAME") = Me.TbUserName.Text
  28. 'Write password to the cookie
  29. Response.Cookies("PBLOGIN").Item("UPASS") = Me.TbPassword.Text
  30. 'If the cookie already exist then wirte the user name and password on the cookie
  31. Else
  32. Response.Cookies("PBLOGIN").Item("UNAME") = Me.TbUserName.Text
  33. Response.Cookies("PBLOGIN").Item("UPASS") = Me.TbPassword.Text
  34. End If
  35. End If
  36. End If
  37.  
  38. Me.VerifyLogin(Me.TbUserName.Text, Me.TbPassword.Text)
  39. End Sub
  40.  
  41. Protected Sub VerifyLogin(ByVal UserName As String, ByVal Password As String)
  42. Try
  43. 'If login credentials are correct
  44. 'Redirect to the user page
  45. 'else
  46. 'prompt user for invalid password
  47. 'end if
  48. Catch ex as System.Exception
  49. Response.Write(ex.Message)
  50. End Try
  51. End Sub
  52.  
  53. Protected Sub lbSignout_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbSignout.Click
  54. 'Check iIf the cookies with name PBLOGIN exist on user's machine
  55. If (Request.Cookies("PBLOGIN") IsNot Nothing) Then
  56. 'Expire the cookie
  57. Response.Cookies("PBLOGIN").Expires = DateTime.Now.AddDays(-30)
  58. End If
  59.  
  60. 'Redirect to the login page
  61. End Sub
  62. End Class
  63.  

[URL snipped]
Last edited by Ezzaral; Jan 18th, 2010 at 1:00 pm. Reason: Added code tags and snipped url. Keep it organized and keep it on site.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ASP.NET Forum


Views: 16731 | Replies: 2
Thread Tools Search this Thread



Tag cloud for ASP.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC