Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Hi folk's

I have a login form in that if i check the remember me check-box,then i want to remember username and password ..

above code is for remember me.. functionality...it is working fine but only one problem ...After checking remember me check box.. if i reload login page the checked remember not remains can any one help me how can i reslove this problem.....


Can any one help me......
My code is in this way..........for remember me .....

Below code is working fine only problem is checked remember is not remains ....
C#
protected void Page_Load(object sender, EventArgs e)
   {
       if (Page.IsPostBack)
       {
           if (chk_rem.Checked)
           {
               HttpCookie mycookie1 = new HttpCookie("mycookie1");
               //Response.Cookies.Remove("mycookie1");

               Response.Cookies.Add(mycookie1);

               mycookie1.Values.Add("Username", txt_username.Text);
               mycookie1.Values.Add("Password", txt_password.Text);
               DateTime dtex = DateTime.Now.AddDays(15);

               if (chk_rem.Checked == true)
               {
                   if (Request.Cookies["mycookie1"] != null)
                   {
                       HttpCookie getcookie1 = Request.Cookies.Get("mycookie1");
                       string un = getcookie1.Values["Username"].ToString();
                       string ps = getcookie1.Values["Password"].ToString();
                   }

               }

           }
           if (chk_rem.Checked == false)
           {
               Response.Cookies["mycookie1"].Expires = DateTime.Now.AddDays(-1);
           }
       }


       if (HttpContext.Current.Request.Cookies["mycookie1"] != null)
       {
           try
           {
               txt_username.Text = HttpContext.Current.Request.Cookies["mycookie1"]["Username"].ToString();
               string a = HttpContext.Current.Request.Cookies["mycookie1"]["Password"].ToString();
               txt_password.Attributes.Add("value", a);

               chk_rem.Checked = true;
           }
           catch { }
       }

   }






Thank's&Regard's
mahesh.b.p.c
Posted
Updated 2-Sep-12 21:03pm
v5
Comments
bbirajdar 30-Aug-12 8:49am    
Why are you posting duplicates ? Use 'Improve Question' button to make changes to your original question. http://www.codeproject.com/Questions/450137/How-to-encrypt-the-cookie
Christian Amado 30-Aug-12 8:53am    
Oops! We have a repost here :) aspnet_regiis -i
bbirajdar 30-Aug-12 8:58am    
:)
mahesh.b.p.c 3-Sep-12 2:56am    
above code is for remember me.. functionality...it is working fine but only one problem ...After checking remember me check box.. if i reload login page the checked remember not remains can any one help me how can i reslove this problem.....

CodeProject Article
[^]

Hope it helps
 
Share this answer
 
Comments
Manas Bhardwaj 30-Aug-12 9:14am    
to the point +5
Christian Amado 30-Aug-12 9:17am    
Thanks :)
Few smart folks created Google[^], which is really free for use.

Even CP has an article on this topic:

Encrypting Cookies to prevent tampering[^]
 
Share this answer
 
Comments
Christian Amado 30-Aug-12 9:01am    
5'ed :)
Manas Bhardwaj 30-Aug-12 9:14am    
thx!
 
Share this answer
 
Comments
Christian Amado 30-Aug-12 9:01am    
5'ed :)
_Amy 30-Aug-12 9:05am    
Thanks. :)
Manas Bhardwaj 30-Aug-12 9:14am    
+5
_Amy 30-Aug-12 9:17am    
Thanks Manas. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900