Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC identity || Disable all cookies and "remember me" option?

I'm using MVC 4 with identity 2.0 and i have in my site (out of the box feature) "Remember me" and i want to disable this option and have one of this two option in my site:

1.user will need to log in (enter username & password) every time he uses my site.

2.user will need to log in every time but the site will remember him for 30 min and not force him to do log-in in that time period(30 min in our situation).

How can i accomplish those 3 things ?

to disable i just comment the check box in the login page i think it will do the trick :)

EDIT:

When i set this :

   app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString("/Logon/LogOn"),
            ExpireTimeSpan = TimeSpan.FromMinutes(30),
        });

Do i need to comment/delete this code from there:

app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login"),
                Provider = new CookieAuthenticationProvider
                {
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
                        validateInterval: TimeSpan.FromMinutes(30),
                        regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
                }
            });

            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
like image 219
Ron Avatar asked Oct 21 '22 02:10

Ron


1 Answers

For disabling "Remember me" pass false as the last parameter in

await userManager.SignInAsync(AuthenticationManager, user, false);

And remove this checkbox from your view.

To make cookie expire in 30 minutes, in your Auth.Config set ExpireTimeSpan to 30 minutes

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
    LoginPath = new PathString("/Logon/LogOn"),
    ExpireTimeSpan = TimeSpan.FromMinutes(30),
});
like image 78
trailmax Avatar answered Oct 23 '22 03:10

trailmax