In this tutorial, I will tell you How to create “Remember Me” Login Page using checkbox with ASP.NET 5 and C#. Whenever you tick Remember Me checkbox it will maintain username and password for web site user using Cookies.

When user click login button that could stores the username and password inside the cookie. First thing you need to do is confirm that the Remember Me checkbox is checked or not, if it's checked then store the username and password inside the cookie to the 1 month and if not checked then set the expiration day to 1 day in else condition to destroy the cookie.

And here is the code that I used:

protected void Page_Load(object sender, EventArgs e)  

      if (!Page.IsPostBack) 
      { 
           if (Request.Cookies["UserName"] != null) 
                txtUserName.Text = Request.Cookies["UserName"].Value; 
           if (Request.Cookies["Password"] != null) 
                txtPassword.Text = Request.Cookies["Password"].Value; 
           if (Request.Cookies["UserName"] != null && Request.Cookies["Password"] != null) 
                chkRember.Checked = true;  
      }  
}  
protected void btnLogin_Click(object sender, EventArgs e) 
 { 
       string stringconnection = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString; 
       MySqlConnection connection = new MySqlConnection(stringconnection); 
      try 
      {  
           int flag = 0; 
           if (chkRember.Checked == true) 
           { 
                Response.Cookies["UserName"].Value = txtUserName.Text; 
                Response.Cookies["Password"].Value = txtPassword.Text; 
                Response.Cookies["UserName"].Expires = DateTime.Now.AddMonths(1); 
                Response.Cookies["Password"].Expires = DateTime.Now.AddMonths(1); 
           } 
           else 
           { 
                Response.Cookies["UserName"].Expires = DateTime.Now.AddMonths(-1); 
                Response.Cookies["Password"].Expires = DateTime.Now.AddMonths(-1); 
           }  
           MySqlCommand com = new MySqlCommand("select * from tbl_user_details", connection); 
           connection.Open(); 
           if (connection.State == ConnectionState.Open) 
           { 
                MySqlDataReader objSqlDataReader;                
                objSqlDataReader = com.ExecuteReader();

                    while (objSqlDataReader.Read())                 
                     { 
                     if (objSqlDataReader[2].ToString().Equals(txtUserName.Text) && objSqlDataReader[5].ToString().Equals(txtPassword.Text)) 
                     { 
                          flag = 1; 
                          Session["UserName"] = txtUserName.Text; 
                          Session["UserType"] = objSqlDataReader[8].ToString(); 
                          Response.Redirect("ContactUs.aspx", false); 
                     } 
                     else 
                     { 
                          ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('Invalid Username and Password')</script>"); 
                    } 
                } 
           } 
      } 
      catch (Exception ex) 
      { 
           lblMsg.Text = ex.ToString(); 
      } 
      finally  
      { 
           connection.Close(); 
      }
 }