Click here to Skip to main content

Implement Remember me on Login Page

Most of website have a "Remember Me" checkbox on their website login page and you do not have to login every time you visit that website. Bellow is a simple implementation for this task: First of all you should know that this is a Cookie based solution and its not safe to store important...
Sign Up to vote bad good
Add a reason or comment to your vote: x
Votes of 3 or less require a comment
See more: C#ASP.NET
Most of website have a "Remember Me" checkbox on their website login page and you do not have to login every time you visit that website.
Bellow is a simple implementation for this task:
First of all you should know that this is a Cookie based solution and its not safe to store important data such ass password in cookies.
now lets get to the code.
First of all import System.Net namespace in your code.
Then add a checkbox control in your login form and name it chkRemember.
then add the following code to click event of your login button:
if (chkRemember.Checked)
{
HttpCookie cookie = new HttpCookie(“YourAppLogin”);
cookie.Values.Add(“username”, txtUsername.Text);
cookie.Expires = DateTime.Now.AddDays(15);
Response.Cookies.Add(cookie);
}
 
In the code above first we check if user has checked "Remember Me"
checkbox, if its checked then we create a HTTPCookie and we set an expiry date for it.
 
Now you should add this code to every page that requires login :
 
if (Request.Cookies["YourApLogin&"] != null)
{
string username = Request.Cookies["YourAppLogin"].Values["username"]);
}
 
This code checks the cookie and returns Username.
Posted 28 Jan '10
Edited 28 Jan '10

Comments
a1sujan - 17 May '11
What do you mean by ("YourAppLogin")? Reply as soon as possible. Thanks
d.bonee - 26 May '11
it is the value or can we say it as a reference name of httpcookie.. HttpCookie cookie = new HttpCookie(“YourAppLogin”);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Your Filters
Interested
Ignored
     
  1. Wonde Tadesse (1,110)
  2. SAKryukov (580)
  3. CRDave1988 (377)
  4. Abhinav S (215)
  1. SAKryukov (10,087)
  2. Christian Graus (6,019)
  3. OriginalGriff (4,956)
  4. Abhinav S (4,550)
  5. thatraja (4,349)

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralVulnerable! PinmemberSalarSoft8:56 28 Jan '10  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web02 | 2.5.120210.1 | Last Updated 28 Jan 2010
Copyright © CodeProject, 1999-2012
All Rights Reserved. Terms of Use
Layout: fixed | fluid