i'm trying to implement remember me functionality on my web site.
Here is on my SignUp master page:
asp:CheckBox ID="rememberMeNow" runat="server"
I'm using ASP.NET Login control in which i set RememberMeSet="True". But it's doesn't work. Then i wrote some code behind where i created cookie after login button click event:
protected void Login1_LoggedIn(object sender, EventArgs e)
{
Timer1.Enabled = true;
string returnUrl = Request.QueryString["ReturnUrl"];
if (!string.IsNullOrEmpty(returnUrl))
{
Response.Redirect("/?file=" + Server.UrlEncode(returnUrl));
}
var rememberMe = PopupLoginView.FindControl("Login1").FindControl("rememberMeNow") as CheckBox;
var emailTextbox = PopupLoginView.FindControl("Login1").FindControl("UserName") as TextBox;
if (rememberMe == null || rememberMe.Checked != true) return;
var cookieRememberMe = new HttpCookie("remember");
if (emailTextbox != null) cookieRememberMe.Values.Add("Email", emailTextbox.Text);
var userprofile = Membership.GetUser();
if (userprofile != null)
Response.Redirect("/");
var textBox = PopupLoginView.FindControl("Login1").FindControl("UserName") as TextBox;
var rememberMe = PopupLoginView.FindControl("Login1").FindControl("rememberMeNow") as CheckBox;
var passTextBox = PopupLoginView.FindControl("Login1").FindControl("Password") as TextBox;
if (textBox != null)
textBox.Focus();
var cookieRemember = Request.Cookies.Get("remember");
if (textBox != null) if (cookieRemember != null) textBox.Text = cookieRemember.Values["Email"];
I want this kind of behaviour: 1.User go to Sign in page for the first time check the remember me checkbox then fill his credentials into fields: username(e-mail address) and password. Then he press button signIn. 2. He comes to the page for the second time
and the credentials are already filled (including password). The problem is that as for me that's very unsafe decision to pass in cookie password field value, even trying to encrypt it before.
On our web site we don't store users passwords so i can't get the password by using username.
If it is possible to implement without code behind by using some asp.net controls please help me with that. The main idea is to enable the ability filing the username and the password for the user.
santino1991
0 Points
1 Post
Problems with implementing “Remember Me” functionality ASP.NET
Feb 22, 2013 03:31 PM|LINK
i'm trying to implement remember me functionality on my web site.
Here is on my SignUp master page:
asp:CheckBox ID="rememberMeNow" runat="server"
I'm using ASP.NET Login control in which i set RememberMeSet="True". But it's doesn't work. Then i wrote some code behind where i created cookie after login button click event:
protected void Login1_LoggedIn(object sender, EventArgs e)
{
Timer1.Enabled = true;
string returnUrl = Request.QueryString["ReturnUrl"];
if (!string.IsNullOrEmpty(returnUrl))
{
Response.Redirect("/?file=" + Server.UrlEncode(returnUrl));
}
var rememberMe = PopupLoginView.FindControl("Login1").FindControl("rememberMeNow") as CheckBox;
var emailTextbox = PopupLoginView.FindControl("Login1").FindControl("UserName") as TextBox;
if (rememberMe == null || rememberMe.Checked != true) return;
var cookieRememberMe = new HttpCookie("remember");
if (emailTextbox != null) cookieRememberMe.Values.Add("Email", emailTextbox.Text);
cookieRememberMe.Expires = DateTime.Now.AddDays(7);
Response.Cookies.Add(cookieRememberMe);
}
On page load i read this cookie:
protected void Page_Load(object sender, EventArgs e)
{
var userprofile = Membership.GetUser();
if (userprofile != null)
Response.Redirect("/");
var textBox = PopupLoginView.FindControl("Login1").FindControl("UserName") as TextBox;
var rememberMe = PopupLoginView.FindControl("Login1").FindControl("rememberMeNow") as CheckBox;
var passTextBox = PopupLoginView.FindControl("Login1").FindControl("Password") as TextBox;
if (textBox != null)
textBox.Focus();
var cookieRemember = Request.Cookies.Get("remember");
if (textBox != null) if (cookieRemember != null) textBox.Text = cookieRemember.Values["Email"];
Response.Cookies["remember"].Expires = DateTime.Now;
}
I want this kind of behaviour: 1.User go to Sign in page for the first time check the remember me checkbox then fill his credentials into fields: username(e-mail address) and password. Then he press button signIn. 2. He comes to the page for the second time and the credentials are already filled (including password). The problem is that as for me that's very unsafe decision to pass in cookie password field value, even trying to encrypt it before.
On our web site we don't store users passwords so i can't get the password by using username.
If it is possible to implement without code behind by using some asp.net controls please help me with that. The main idea is to enable the ability filing the username and the password for the user.
smirnov
All-Star
23576 Points
4049 Posts
Re: Problems with implementing “Remember Me” functionality ASP.NET
Feb 23, 2013 06:51 AM|LINK
"Remember me next time" not working for Login control? Here's why!
Hope it helps.