Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
in my login page i have one check bix is there.i.e., remember me .Now i want to check next time login with same userid it will take that password.How can i write code? Any body can send Code for this Question?
Posted
Updated 12-May-12 7:16am
v2

Use ASP.NET Login Control[^]. It has a feature for Remember Me next time.
 
Share this answer
 
Comments
Manas Bhardwaj 12-May-12 13:26pm    
Good answer. My 5!
Wonde Tadesse 13-May-12 10:17am    
Thanks
Maciej Los 12-May-12 19:29pm    
Good answer, +5!
Wonde Tadesse 13-May-12 10:17am    
Thanks
VJ Reddy 12-May-12 23:15pm    
Good reference. 5!
Basically, you can achieve this functionality using cookies.

For the first time, check:
C#
if (chkRememberPassword.Checked == true)
{
   Response.Cookies["UserName"].Value = txtUserName.Text;
   Response.Cookies["Password"].Value = txtPassword.Text;

   // set cookie expiration in a month
   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);
}


And do the following in your Page_Load:
C#
if (!IsPostBack)
{
   // If cookie exists then set the values from before
   if (Request.Cookies["UserName"] != null)
      txtUserName.Text= Request.Cookies["UserName"].Value;
   if (Request.Cookies["Password"] != null)
      txtPassword.Text.Attributes.Add("value", Request.Cookies["Password"].Value);
   if (Request.Cookies["UserName"] != null && Request.Cookies["UserName"] != null)
      chkRememberPassword.Checked = true;
}


Try!
 
Share this answer
 
Comments
VJ Reddy 12-May-12 23:15pm    
Good answer. 5!
Sandeep Mewara 13-May-12 1:07am    
Thanks.
Hari Krishna Prasad Inakoti 14-May-12 3:26am    
thanq sandeep
Sandeep Mewara 14-May-12 8:30am    
Welcome.

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