Identity: Make password validator options get public

Created on 20 Dec 2016  路  10Comments  路  Source: aspnet/Identity

I want to show the current password rules on a webpage, without having to hardcode it in HTML. How do I get the current rules?

An example:

<p>Minimum password length: @PasswordRules.RequiredLength</p>
3 - Done Features

All 10 comments

@Saticmotion
In Identity 2.x

//or as CustomPasswordValidator
var rules = (UserManager.PasswordValidator as PasswordValidator); 
rules.RequireDigit;
rules.RequiredLength;

In Identity Core

var rules = UserManager.Options.Password;
rules.RequiredLength
rules.RequireLowercase
rules.RequireUppercase

you can try

@maliming I'm using .NET Core, so I tried your second option. But it doesn't work, since Options is protected internal. I'm using the "Microsoft.AspNetCore.Identity.EntityFramewordCore" package, version 1.1.0.

@Saticmotion
Derive a class from UserManager

test

services.AddIdentity(.....).AddUserManager<MyUserManager>();

I do not know if this is a best practice, you can wait for the official proposal.

This works, thank you! Though it's kind of annoying I have to solve it this way.

@Saticmotion your controller can obtain the same IOptions<IdentityOptions> singleton from DI that the UserManager gets in its constructor: https://github.com/aspnet/Identity/blob/dev/src/Microsoft.AspNetCore.Identity/UserManager.cs#L75.

BTW I am not against making the property getter public in 2.0. cc @HaoK

DI Is a best practice.馃榿

@divega That's probably a better option. Thanks!!

Reopening so that we can consider making the property getter public.

b64a32f089f06c8c403f8bb9ee085a580c9555e2

Was this page helpful?
0 / 5 - 0 ratings