Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Gordon Saxby 1459 posts 1880 karma points
    Jun 13, 2024 @ 16:17
    Gordon Saxby
    0

    Member Login page with Remember Me

    I am using some code that I "obtained" from another site, but it's not quite working as expected.

        if (await _memberManager.ValidateCredentialsAsync(model.Email, model.Password))
        {
            var result = await _memberSignInManager.PasswordSignInAsync(model.Email, model.Password, false, true);
    
            if (result.Succeeded)
            {
                return Redirect(model.RedirectUrl!);
            }
        }
    

    There is also a "Remember me" checkbox on the form.

    The login works, but a cookie is stored with a life of 1 year, even if the Remember Me option is not ticked.

    The 3rd parameter in PasswordSignInAsync is "is Persistent" - shouldn't it not persist if that is set to false? And is that what the "Remember Me" option should affect?

    Finally, can I alter the lifespan of the cookie?

  • Huw Reddick 1920 posts 6648 karma points MVP 2x c-trib
    Jun 13, 2024 @ 16:32
    Huw Reddick
    0

    that is because you are allways setting the value to false

    PasswordSignInAsync(model.Email, model.Password, **false**, true)
    

    You need to set that to the value from your model.RememberMe

  • Gordon Saxby 1459 posts 1880 karma points
    Jun 13, 2024 @ 21:47
    Gordon Saxby
    0

    Yes, but my question was - shouldn’t it NOT persist if that value is false?

    Currently I am getting a cookie with a 1 year expiry date. And the login persists between browser sessions and I assume it shouldn’t (when the setting is false)?

  • Huw Reddick 1920 posts 6648 karma points MVP 2x c-trib
    Jun 14, 2024 @ 11:06
    Huw Reddick
    0

    Which version of Umbraco are you using? I am not seeing this behaviour

  • Gordon Saxby 1459 posts 1880 karma points
    Jun 14, 2024 @ 12:44
    Gordon Saxby
    0

    v13 - new site build.

    Currently - running locally while developing in Visual Studio, if I log in, close the browser (stop the site), then restart it, the user is still logged in. I want them not to be if they didn't tick "Remember me"., which they aren't at the moment because I am always sending "false" to "isPersistent" (3rd param)

  • Huw Reddick 1920 posts 6648 karma points MVP 2x c-trib
    Jun 14, 2024 @ 17:16
    Huw Reddick
    0

    Are you referring to back-office users or frontend members?

  • Gordon Saxby 1459 posts 1880 karma points
    Jun 14, 2024 @ 21:35
    Gordon Saxby
    0

    Sorry, I should have been clearer - I am talking about Members. Signing in to a front-end Members area.

  • Huw Reddick 1920 posts 6648 karma points MVP 2x c-trib
    Jun 15, 2024 @ 05:53
    Huw Reddick
    0

    Try clearing cookies in case you have any old ones getting in the way. Have you made any other changes to the code?

    This is not the behavior I am seeing.

Please Sign in or register to post replies

Write your reply to:

Draft