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!
 
 
 


 Sent from my iDevice. 

Tags:

Asp.net

Calendar

<<  May 2024  >>
MoTuWeThFrSaSu
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

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

"Courage is fear holding on a minute longer"
General George Patton Jr