Remember Me checkbox

by ssi 4. July 2013 18:10

 

Create a cookie and store the user id and password.On the blur event of textbox of userid access the password from the cookie and set it.then do this code on Login1_LoggedIN Event like below
protected void Login1_LoggedIN(object sender, EventArgs e)
{
CheckBox rm = (CheckBox)Login1.FindControl("RememberMe");
if (rm.Checked)
{
HttpCookie myCookie = new HttpCookie("myCookie");
Response.Cookies.Remove("myCookie");
Response.Cookies.Add(myCookie);
myCookie.Values.Add("Email"this.Login1.UserName.ToString());
myCookie.Values.Add("Pass"this.Login1.Password.ToString());
DateTime dtExpiry = DateTime.Now.AddDays(15); //you can add years and months too here
Response.Cookies["myCookie"].Expires = dtExpiry;
}
}
and then do this code on Page_Load Event
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.Cookies["myCookie"] != null)
{
HttpCookie cookie = Request.Cookies.Get("myCookie");
string emailID = cookie.Values["Email"].ToString();
string password = cookie.Values["Pass"].ToString();
if (Membership.ValidateUser(emailID, password))
{
FormsAuthentication.RedirectFromLoginPage(emailID, true);
}
}
}
}

<asp:Login ID="Login1" runat="server" OnLoggedIn="Login1_LoggedIN" />

 
 
Becky replied to Becky on 24-Jan-11 11:43 AM
Thank you! It woked!
 
 
 

http://www.nullskull.com/q/10250114/remember-me-checkbox.aspx


 Sent from my iDevice. 

Tags:

Asp.net

Add comment

biuquote
  • Comment
  • Preview
Loading

Calendar

<<  March 2026  >>
MoTuWeThFrSaSu
2324252627281
2345678
9101112131415
16171819202122
23242526272829
303112345

View posts in large calendar

RecentComments

None

Development Team @ Shelbysys

We develop custom database applications for our clients. Our development tool of choice is MS Visual Studio. 

Quotations

"Fill the unforgiving minute with sixty seconds worth of distance run."
Rudyard Kipling