How do I define the password rules for Identity in ASP.NET 5 MVC 6 (vNext)?

后端 未结 4 1910
旧时难觅i
旧时难觅i 2020-12-29 01:42

The default Identity provider provided in ASP.NET 5 has very strict password rules by default, requiring a lower case character, an upper case character, a non-alphanumeric

4条回答
  •  生来不讨喜
    2020-12-29 02:30

    I actually ended up figuring this out, it turns out you need to supply AddDefaultIdentity with a suitable lambda expression that configures the IdentityOptions it provides. This is done inside the ConfigureServices method within the Startup class, like so:

    public class Startup {
        public void ConfigureServices(IServiceCollection services) {
    
            // Add Identity services to the services container.
            services.AddDefaultIdentity(Configuration,
                o => {
                    o.Password.RequireDigit = false;
                    o.Password.RequireLowercase = false;
                    o.Password.RequireUppercase = false;
                    o.Password.RequireNonLetterOrDigit = false;
                    o.Password.RequiredLength = 7;
                });
        }
    }
    

    Update 2:

    The above was true in the beta1 versions of the framework, in the latest rc1 beta5 it has changed slightly to:

    services.AddIdentity(o => {
        // configure identity options
        o.Password.RequireDigit = false;
        o.Password.RequireLowercase = false;
        o.Password.RequireUppercase = false;
        o.Password.RequireNonAlphanumeric = false;
        o.Password.RequiredLength = 6;
    })
    .AddEntityFrameworkStores()
    .AddDefaultTokenProviders();
    

提交回复
热议问题