Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Remember Me

Remember Me

Scheduled Pinned Locked Moved ASP.NET
securityhelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    janani13
    wrote on last edited by
    #1

    Hi all, Im using a login control in my application.In that the Remember me check box is not working fine.when i close the app. and open in a new tab the session maintains. But when i close the browser and open in a new browser i cant able to open the application.Solve my problem please. code behind:

    void Login1_LoggingIn(object sender, LoginCancelEventArgs e)
    {
    string username = Login1.UserName.Trim();
    if (!string.IsNullOrEmpty(username))
    {
    MembershipUser user = Membership.GetUser(username);
    if (user != null)
    {
    // Only adjust the UserName if the password is correct. This is more secure
    // so a hacker can't find valid usernames if we adjust the case of mis-cased
    // usernames with incorrect passwords.

                if (Membership.ValidateUser(user.UserName, Login1.Password))
                {
                    Login1.UserName = user.UserName;
                    CheckBox Remember = (CheckBox)Login1.FindControl("RememberMe");
    
                    if (Remember.Checked == true)
                    {
                        Response.Cookies\["UserName"\].Value = Login1.UserName;
                        Response.Cookies\["UserName"\].Expires = DateTime.Now.AddDays(7);
                        Response.Cookies\["Password"\].Value = Login1.Password;
                        Response.Cookies\["Password"\].Expires = DateTime.Now.AddDays(7);
                    }
                    else
                    {
                        Response.Cookies\["UserName"\].Expires = DateTime.Now.AddDays(-7);
                        Response.Cookies\["Password"\].Expires = DateTime.Now.AddDays(-7);
                    }
    

    ......

    Web config:

    <authentication mode="Forms">
    <forms timeout="30" protection="All"
    slidingExpiration="true" loginUrl="http://localhost/OliveTreeNetwork/login.aspx" cookieless="UseCookies"/>
    </authentication>

    M 1 Reply Last reply
    0
    • J janani13

      Hi all, Im using a login control in my application.In that the Remember me check box is not working fine.when i close the app. and open in a new tab the session maintains. But when i close the browser and open in a new browser i cant able to open the application.Solve my problem please. code behind:

      void Login1_LoggingIn(object sender, LoginCancelEventArgs e)
      {
      string username = Login1.UserName.Trim();
      if (!string.IsNullOrEmpty(username))
      {
      MembershipUser user = Membership.GetUser(username);
      if (user != null)
      {
      // Only adjust the UserName if the password is correct. This is more secure
      // so a hacker can't find valid usernames if we adjust the case of mis-cased
      // usernames with incorrect passwords.

                  if (Membership.ValidateUser(user.UserName, Login1.Password))
                  {
                      Login1.UserName = user.UserName;
                      CheckBox Remember = (CheckBox)Login1.FindControl("RememberMe");
      
                      if (Remember.Checked == true)
                      {
                          Response.Cookies\["UserName"\].Value = Login1.UserName;
                          Response.Cookies\["UserName"\].Expires = DateTime.Now.AddDays(7);
                          Response.Cookies\["Password"\].Value = Login1.Password;
                          Response.Cookies\["Password"\].Expires = DateTime.Now.AddDays(7);
                      }
                      else
                      {
                          Response.Cookies\["UserName"\].Expires = DateTime.Now.AddDays(-7);
                          Response.Cookies\["Password"\].Expires = DateTime.Now.AddDays(-7);
                      }
      

      ......

      Web config:

      <authentication mode="Forms">
      <forms timeout="30" protection="All"
      slidingExpiration="true" loginUrl="http://localhost/OliveTreeNetwork/login.aspx" cookieless="UseCookies"/>
      </authentication>

      M Offline
      M Offline
      Mike Ellison
      wrote on last edited by
      #2

      For version 2.0 the ASP.NET team changed the timeout for persistent cookies to use the <forms timeout=""/> attribute. So the life of the persistent cookie then matches the lifetime of session based cookies. In your example, the cookie will last 30 minutes.

      www.MishaInTheCloud.com

      J 1 Reply Last reply
      0
      • M Mike Ellison

        For version 2.0 the ASP.NET team changed the timeout for persistent cookies to use the <forms timeout=""/> attribute. So the life of the persistent cookie then matches the lifetime of session based cookies. In your example, the cookie will last 30 minutes.

        www.MishaInTheCloud.com

        J Offline
        J Offline
        janani13
        wrote on last edited by
        #3

        Hi Mike, Even if i extend the timeout value i cant the expected results.What to do with this.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups