How do I get a hold of an instance of IPasswordConfiguration?
I Have a need for accessing the minimum password length in code, and I see that this value can be found by accessing an instance of IPasswordConfiguration. The ultimate source is normally the security settings in appSettings.json.
At this point the only way to do this that I've found is to inject an IMemberManager instance, typecast it to MemberManager, and access the MemberManager.PasswordConfiguration property. That's obviously a bit of a hack, is there a better way?
public MyController(IMemberManager memberManager)
{
if (memberManager is MemberManager memberManagerImpl)
{
var pwdConfig = memberManagerImpl.PasswordConfiguration;
int minLength = pwdConfig.RequiredLength;
}
}
To use them in code you will need to do the following :
public MyController(IOptions<SecuritySettings> securitySettings)
{
int minMemberPwLength = this.securitySettings.Value.MemberPassword.RequiredLength;
int minUserPwLength = this.securitySettings.Value.UserPassword.RequiredLength;
}
Thanks Dave, that's exactly what I was looking for. I may have ignored that approach because I was afraid the IOptions<> wouldn't contain the default settings, but they do indeed contain defaults, e.g. RequiredLength = 10 if you don't specify it in appSettings.json.
A small hint to the documentation team to include a paragraph or two on how to access the settings in code.
How do I get a hold of an instance of IPasswordConfiguration?
I Have a need for accessing the minimum password length in code, and I see that this value can be found by accessing an instance of IPasswordConfiguration. The ultimate source is normally the security settings in appSettings.json.
At this point the only way to do this that I've found is to inject an IMemberManager instance, typecast it to MemberManager, and access the MemberManager.PasswordConfiguration property. That's obviously a bit of a hack, is there a better way?
Can't you just inject IPasswordConfiguration ?
Ignore that, you can't just inject IPasswordConfiguration
Hi Tor,
You can find the required settings here. https://docs.umbraco.com/umbraco-cms/reference/configuration/securitysettings
To use them in code you will need to do the following :
Dave
Thanks Dave, that's exactly what I was looking for. I may have ignored that approach because I was afraid the IOptions<> wouldn't contain the default settings, but they do indeed contain defaults, e.g. RequiredLength = 10 if you don't specify it in appSettings.json.
A small hint to the documentation team to include a paragraph or two on how to access the settings in code.
is working on a reply...