C# .NET - remember password

Asked By rama chandran on 17-May-10 07:51 AM
hi friends,



            in .net i am using visual web developer 2008 express edition version now i want to know in my project.

i want an option for remember the password when i click the submit button in login page what is the coding for that. send me.
Anoop S replied to rama chandran on 17-May-10 07:57 AM
First just add a checkbox (I havn't renamed it in this sample, just calling it CheckBox1) in your login form:



Then in your code handler for the button click:

 
 
private void btnLogin_Click(object sender, System.EventArgs e)  
{  
    if ( FormsAuthentication.Authenticate(txtID.Text, txtPwd.Text) )  
    { //It went well         FormsAuthentication.RedirectFromLoginPage(txtID.Text,CheckBox1.Checked);  
    }  
    else  
    {  
    LabelError.Text = "Error logging in";  
    }  
} 
So the last parameter to RedirectFromLoginPage is CheckBox1.Checked which will then handle everything from us.

Super Man replied to rama chandran on 17-May-10 08:08 AM
remember password is the utility of browser.

but as you say "remember me for next time", is done by the cookies.

if you select remember me next time , then it creates cookies to your localcomputer.

and next times it checks for the cookies in your computer .

if cookie exists, then it reads content,and sever finds its "OK",

then it makes login with data specified in the cookie.
Super Man replied to rama chandran on 17-May-10 08:16 AM

        // if user makes susccessful login then create cookie

        // it creates cookies and stores in to local computer

        HttpCookie cookie = new HttpCookie("www.google.com");

        cookie["username"] = "mr.khan";

        cookie["password"] = "123456";

        Response.Cookies.Add(cookie);

 

 

 

        // read this cookie in login page_load event if it exists

        HttpCookie cook = Request.Cookies["www.google.com"];

        string uname = cook["username"].ToString();

        string pwd = cook["password"].ToString();