“REMEMBER ME” FUNCTIONALITY IN A LOGIN FORM

Takeshi Okada

Total Post:89

Points:629
Posted by  Takeshi Okada
 1380  View(s)
Ratings:
Rate this:

I am using linq to entity connection. I want to keep user logged in once he entered into his account, This is my code. It's not working. Help, please

    if (this.ChkRememberme != null && this.ChkRememberme.Checked == true)

    {

        HttpCookie cookie = new HttpCookie(TxtUserName.Text, TxtPassword.Text);

        cookie.Expires.AddYears(1);

        Response.Cookies.Add(cookie);

    }

  1. Pravesh Singh

    Post:412

    Points:2888
    Re: “Remember me” functionality in a Login form

    Hi Takeshi,


    Try this :

    if (this.ChkRememberme != null && this.ChkRememberme.Checked == true)

        {

     int timeout = rememberMe ? 525600 : 30; // Timeout in minutes, 525600 = 365 days.

        var ticket = new FormsAuthenticationTicket(TxtUserName.Text, TxtPassword.Text);

        string encrypted = FormsAuthentication.Encrypt(ticket);

        var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted);

        cookie.Expires = System.DateTime.Now.AddMinutes(timeout);

        cookie.HttpOnly = true; // cookie not available in javascript.

        Response.Cookies.Add(cookie);

    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!