Home > ASP.Net > Login credentials storing (Remember me Option)

Login credentials storing (Remember me Option)


Hi

try this:

Use this code:

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 way

protected 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);
}

Good Luck

Advertisements
Categories: ASP.Net
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: