how to create a remember me checkbox in the login page?
how to add the feature to my website
Simply drag a Login control to your page and set the
DisplayRememberMe property to True
Wildoo
does it work like cookies?
Yes, When using
Forms authentication, ASP.NET will create a cookie (you don't need to do that yourself as suggested in other posts). When you don't use the remember me option, a Non persitant cookie is created, which will be deleted after you close the browser. When the
remember me checkbox is checked, a persitant cookie is created. Both cookie have a expire time. The timespan depands on the
TimeOut Property in the Forms Section on web.config, which default to 30 (minutes), so when you want to let you users be authenticated even after some days or weeks, you need to set this to a much higher value.
Be aware that the expiry date is not updated on each and every request, but only if more than half of the Timeout interval has elapsed:
The
remember me option is inubuilt in login ocnbtrol, but we need write code to work on that. To we can use the Cookies and store values and then read and can use.
if (UserRow.RoleID == (int)eRoles.Administrator) Response.Redirect("~/Default.aspx"); }
protectedvoid btnLogOut_Click(object sender, EventArgs e) { Session.Abandon(); HttpCookie cookie = Request.Cookies.Get(IMASHOPS_LOGIN); // do not use Remove method to remove cookie. also Do not use DateTime.MinValue, they do not work cookie.Expires = DateTime.Now.AddYears(-30); Response.Cookies.Add(cookie); Response.Redirect("~/Login.aspx"); }
Wildoo
Member
586 Points
757 Posts
Remember me on login page?
Apr 12, 2012 10:58 PM|LINK
how to create a remember me checkbox in the login page?
how to add the feature to my website
does it work like cookies?
please provide me wih articles and source code
thanks in advance
Phinehas
Member
361 Points
238 Posts
Re: Remember me on login page?
Apr 13, 2012 02:03 AM|LINK
The following link have a sample code. Please take a look at it:
http://www.eggheadcafe.com/community/csharp/2/10110416/login-with-remember-me-option.aspx
ddredstar@ho...
Member
351 Points
116 Posts
Re: Remember me on login page?
Apr 13, 2012 02:19 AM|LINK
try this
if (Membership.ValidateUser(userName.Text, password.Text)) { if (Request.QueryString["ReturnUrl"] != null) { FormsAuthentication.RedirectFromLoginPage(userName.Text, rememberme.checked); } else { FormsAuthentication.SetAuthCookie(userName.Text, rememberme.checked); } } else { Response.Write("Invalid UserID and Password"); }tarunSaini
Contributor
2948 Points
985 Posts
Re: Remember me on login page?
Apr 13, 2012 02:44 AM|LINK
check this link
http://asp-net-example.blogspot.in/2009/01/aspnet-cookie-example-how-to-create.html
priyankmtr
Contributor
2626 Points
526 Posts
Re: Remember me on login page?
Apr 13, 2012 05:11 AM|LINK
after successfully login, add code like this :-
if (chkRemember.Checked)
{
HttpCookie User = new HttpCookie("UserName", email);
HttpCookie SBPassword = new HttpCookie("UserPassword", txtPassword.Text);
HttpCookie Remember = new HttpCookie("UserRemember", "True");
User.Expires = DateTime.Now.AddMonths(3);
Response.Cookies.Add(User);
SBPassword.Expires = DateTime.Now.AddMonths(3);
Response.Cookies.Add(SBPassword);
Remember.Expires = DateTime.Now.AddMonths(3);
Response.Cookies.Add(Remember);
}
else
{
HttpCookie User = new HttpCookie("UserName", "");
HttpCookie SBPassword = new HttpCookie("UserPassword", "");
HttpCookie Remember = new HttpCookie("UserRemember", "False");
User.Expires = DateTime.Now.AddMonths(3);
Response.Cookies.Add(User);
SBPassword.Expires = DateTime.Now.AddMonths(3);
Response.Cookies.Add(SBPassword);
Remember.Expires = DateTime.Now.AddMonths(3);
Response.Cookies.Add(Remember);
}
(Mark as Answer If you find helpful)
hans_v
All-Star
35986 Points
6550 Posts
Re: Remember me on login page?
Apr 13, 2012 09:05 AM|LINK
Simply drag a Login control to your page and set the DisplayRememberMe property to True
Yes, When using Forms authentication, ASP.NET will create a cookie (you don't need to do that yourself as suggested in other posts). When you don't use the remember me option, a Non persitant cookie is created, which will be deleted after you close the browser. When the remember me checkbox is checked, a persitant cookie is created. Both cookie have a expire time. The timespan depands on the TimeOut Property in the Forms Section on web.config, which default to 30 (minutes), so when you want to let you users be authenticated even after some days or weeks, you need to set this to a much higher value.
Be aware that the expiry date is not updated on each and every request, but only if more than half of the Timeout interval has elapsed:
http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.slidingexpiration.aspx
More info on forms authentication
http://www.asp.net/web-forms/tutorials/security
http://www.asp.net/web-forms/videos/authentication
viral sarvai...
Participant
848 Points
268 Posts
Re: Remember me on login page?
Apr 13, 2012 09:26 AM|LINK
if (chkRememberMe.Checked == true) { //Create Cookie to Store Info HttpCookie aCookie = new HttpCookie("Info"); aCookie.Values["userName"] = txtUsername.Text; aCookie.Values["Password"] = txtPassword.Text; aCookie.Expires = DateTime.Now.AddDays(10); Response.Cookies.Add(aCookie); }Blogs : http://codesimplified.com
sriramabi
Contributor
4351 Points
1277 Posts
Re: Remember me on login page?
Apr 13, 2012 09:37 AM|LINK
hai
<div style="margin: 0px; padding: 0px; border-width: 0px; outline-width: 0px; font-size: 13px; vertical-align: baseline; background-color: transparent;">You can use cookies to save user name in login controls authenticate event and populate user name text box in onload event using this cookie
sample code for onload
sample code for authenticate
thank u</div>sriramabi
Contributor
4351 Points
1277 Posts
Re: Remember me on login page?
Apr 13, 2012 09:39 AM|LINK
hi
The remember me option is inubuilt in login ocnbtrol, but we need write code to work on that. To we can use the Cookies and store values and then read and can use.
Here my code in easier way
hans_v
All-Star
35986 Points
6550 Posts
Re: Remember me on login page?
Apr 13, 2012 09:45 AM|LINK
No, you don't need to write a single line of code behind. Everything can be set in web.config....