0

I am working in asp.net and c#.In my application i have login page for which i am having remember me feature.My code works well in firefox but not working in chrome and IE.please let me know where i went wrong..

CODE:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        if (Request.Cookies["Usermail"].Value != null &&      Request.Cookies["userpass"].Value != null)
        {
            txtemail.Text = Request.Cookies["Usermail"].Value;
           txtpassword.Attributes["value"] = DecryptString(Request.Cookies["userpass"].Value);
        }
    }

}

protected void btnlogin_Click1(object sender, EventArgs e)
{
 if (chkremember.Checked)
        {
            ck.Expires = tkt.Expiration;
            Response.Cookies["userpass"].Value = EnryptString(txtpassword.Text);
            Response.Cookies["Usermail"].Value = txtemail.Text;
            Response.Cookies["Usermail"].Expires = DateTime.Now.AddDays(30);
            Response.Cookies["userpass"].Expires = DateTime.Now.AddDays(30);
        }

}

NOTE:Here EnryptString(); and DecryptString(); are methods for encrypting and decrypting the password..

smith269
  • 135
  • 2
  • 4
  • 15

1 Answers1

0

you can use code like below:

   if (!IsPostBack)
   {
     if (Request.Cookies["userinfo"] != null)
        {
            HttpCookie objCookie = Request.Cookies["userinfo"];
            txtUserName.Text = objCookie.Values["username"];
            txtPassword.Attributes.Add("value", objCookie.Values["password"]);
            chkRemember.Checked = true;
        }
   }

   protected void btnlogin_Click1(object sender, EventArgs e)
   {
      if (chkremember.Checked)
       {

            if (Request.Cookies["userinfo"] != null)
            {
                HttpCookie objCookie = Request.Cookies["userinfo"];
                objCookie.Values.Remove("username");
                objCookie.Values.Remove("password");
                objCookie.Values["username"] = txtUserName.Text.Trim();
                objCookie.Values["password"] = txtPassword.Text.Trim();
                objCookie.Expires = DateTime.Now.AddDays(30);
                Response.Cookies.Add(objCookie);
            }
            else
            {
                HttpCookie objCookie = new HttpCookie("userinfo");
                objCookie.Values["username"] = txtUserName.Text.Trim();
                objCookie.Values["password"] = txtPassword.Text.Trim();
                objCookie.Expires = DateTime.Now.AddDays(30);
                Response.Cookies.Add(objCookie);
            }
       }

   }
user1990587
  • 386
  • 4
  • 15