RememberMe option to remember only username using asp:login?
-
Hi, I have created my application using asp:login control. I need to make the login control to remember only the username on next login. Any luck? - Rams.
Be simple and Be sample.
Hi Rams, Refer to the following code that uses a CheckBox and gives the flexibility to the user to save the username:
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { CheckBox cek = (CheckBox)Login1.FindControl("RememberMe"); if (Request.Cookies["username"] == null Request.Cookies["username"].Value.ToString().Trim() == "") { cek.Checked = false; } else { Login1.UserName = Request.Cookies["username"].Value.ToString(); } } } protected void Login1_LoggingIn(object sender, LoginCancelEventArgs e) { CheckBox cek = (CheckBox)Login1.FindControl("RememberMe"); if (cek.Checked == true) { HttpCookie cookie = new HttpCookie("username"); cookie.Value = Login1.UserName; cookie.Expires = DateTime.Now.AddDays(1);//cookie Expires HttpContext.Current.Response.AppendCookie(cookie); } else { HttpContext.Current.Response.Cookies.Remove("username"); } cek.Checked = false; }
//--- another wayprotected void Page_Load(object sender, EventArgs e) { if (Request.Cookies["MyCookie"] != null) { TextBox pass = (TextBox)Login1.FindControl("Password"); pass.Attributes.Add("value", Request.Cookies["MyCookie"]["password"]); Login1.UserName = Request.Cookies["MyCookie"]["username"]; } } protected void Login1_LoggedIn(object sender, EventArgs e) { HttpCookie cookie1 = new HttpCookie("MyCookie"); cookie1.Values.Add("username", Login1.UserName); cookie1.Values.Add("password", Login1.Password); cookie1.Expires = DateTime.Now.AddDays(1);//cookie Expires HttpContext.Current.Response.AppendCookie(cookie1); }
I hope this would be helpful. For more information on this refer to the following links: Overview of Forms Authentication[^] How to implement simple Form Authentication[^]John Adams ComponentOne LLC. www.componentone.com
-
Hi Rams, Refer to the following code that uses a CheckBox and gives the flexibility to the user to save the username:
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { CheckBox cek = (CheckBox)Login1.FindControl("RememberMe"); if (Request.Cookies["username"] == null Request.Cookies["username"].Value.ToString().Trim() == "") { cek.Checked = false; } else { Login1.UserName = Request.Cookies["username"].Value.ToString(); } } } protected void Login1_LoggingIn(object sender, LoginCancelEventArgs e) { CheckBox cek = (CheckBox)Login1.FindControl("RememberMe"); if (cek.Checked == true) { HttpCookie cookie = new HttpCookie("username"); cookie.Value = Login1.UserName; cookie.Expires = DateTime.Now.AddDays(1);//cookie Expires HttpContext.Current.Response.AppendCookie(cookie); } else { HttpContext.Current.Response.Cookies.Remove("username"); } cek.Checked = false; }
//--- another wayprotected void Page_Load(object sender, EventArgs e) { if (Request.Cookies["MyCookie"] != null) { TextBox pass = (TextBox)Login1.FindControl("Password"); pass.Attributes.Add("value", Request.Cookies["MyCookie"]["password"]); Login1.UserName = Request.Cookies["MyCookie"]["username"]; } } protected void Login1_LoggedIn(object sender, EventArgs e) { HttpCookie cookie1 = new HttpCookie("MyCookie"); cookie1.Values.Add("username", Login1.UserName); cookie1.Values.Add("password", Login1.Password); cookie1.Expires = DateTime.Now.AddDays(1);//cookie Expires HttpContext.Current.Response.AppendCookie(cookie1); }
I hope this would be helpful. For more information on this refer to the following links: Overview of Forms Authentication[^] How to implement simple Form Authentication[^]John Adams ComponentOne LLC. www.componentone.com
This is good, But I am validating login thru membership provider. My problem is, it will login automatically without asking the user name and password when I choose "RememberMe" option checked. I need login control needs to remember only username using "RememberMe" option and password alwasy user needs to enter. Any luck? - Rams.
Be simple and Be sample.
-
This is good, But I am validating login thru membership provider. My problem is, it will login automatically without asking the user name and password when I choose "RememberMe" option checked. I need login control needs to remember only username using "RememberMe" option and password alwasy user needs to enter. Any luck? - Rams.
Be simple and Be sample.