Search code examples
c#asp.net-mvcasp.net-identityasp.net-identity-3

Cant find PasswordValidator property in UserManager, AspNet.Identity 3


I want to change the password requirements for my registration form but I cant find the PasswordValidator property in the UserManager class.

I'm using AspNet.Identity.EntityFramework 3.0.0-beta5

private readonly UserManager<AppUser> _userManager;
        private readonly SignInManager<AppUser> _signInManager;

        public AccountController(UserManager<AppUser> userManager, SignInManager<AppUser> signInManager)
        {

            _userManager = userManager;
            _signInManager = signInManager;

            // UserManager does not contain a definition for PasswordValidator
            //_userManager.PasswordValidator

        }

(For comparison, in Microsoft ASP.NET Identity 2.0, documentation for UserManager<TUser, TKey>.PasswordValidator is here.)


Solution

  • So I managed to fix it by changing the identity options in my startup.cs

    This is what it looked like before

        services.AddIdentity<Models.Identity.AppUser, IdentityRole>()
           .AddEntityFrameworkStores<test.Models.Identity.IdentityDataContext>();
    

    This is what it looks like now

    services.AddIdentity<Models.Identity.AppUser, IdentityRole>(options =>
                {
                    options.Password.RequireDigit = false;
                    options.Password.RequiredLength = 6;
                    options.Password.RequireLowercase = false;
                    options.Password.RequireNonLetterOrDigit = false;
                    options.Password.RequireUppercase = false;
                })
                    .AddEntityFrameworkStores<test.Models.Identity.IdentityDataContext>();