Anand N

Anand N

  • NA
  • 19
  • 30.6k

How to store password in cookies?

Oct 17 2012 2:11 AM
plz go through the following code and give solution to me..... Thanks a lot


public partial class Home : System.Web.UI.Page
    {
        HttpCookie cookie = new HttpCookie("userdetails");                   
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Cookies["userdetails"] != null)
            {

                txtUsername.Text = Request.Cookies["userdetails"]["username"];

                txtPassword.Text = Request.Cookies["userdetails"]["Password"];                            // it is not working
            }
            if (!IsPostBack)
            {
                lblViewersCount.Text = "You are the Viewer Number " + Application["ViewersCount"].ToString();
            }

        }

        protected void button_click(object sender, ImageClickEventArgs e)
        {
            cookie.Values["username"] = txtUsername.Text;
            cookie.Values["Password"] = txtPassword.Text;                    // password value is not assigning to the cookie so while retrieving it is giving null value
            cookie.Expires = DateTime.Now.AddDays(1);
            Response.Cookies.Add(cookie);
          
        }

    }

Answers (2)