Reputation: 1874
This autogenerated code registers a new user:
var manager = new AuthenticationIdentityManager(new IdentityStore());
User u = new User(userName) { UserName = userName };
IdentityResult result = manager.Users.CreateLocalUser(u, Password.Text);
if (result.Success)
{ ... }
How can we change password validation settings?
This is what I've found using dotPeek:
AuthenticationIdentityManager class instance contains UserManager which validates a password using PasswordValidator:
From class Microsoft.AspNet.Identity.UserManager:
result = this.PasswordValidator.Validate(password);
internal IStringValidator PasswordValidator
{
get
{
return this.Manager.Settings.GetIdentityOptions().PasswordValidator;
}
}
Class Microsoft.AspNet.Identity.IdentityOptions:
public IdentityOptions()
{
this._defaultPasswordValidator = new IdentityOptions.DefaultPasswordValidator(this);
this._defaultUserNameValidator = new IdentityOptions.DefaultUserNameValidator(this);
this.MinRequiredPasswordLength = 6;
this.LocalLoginProvider = "Local";
}
public IStringValidator PasswordValidator
{
get
{
return this._passwordValidator ?? (IStringValidator) this._defaultPasswordValidator;
}
set
{
this._passwordValidator = value;
}
}
I cannot find where IdentityOptions instance can be accessed or replaced. Is there any example or documentation?
Upvotes: 1
Views: 1509
Reputation: 5807
RTM version seems to have dropped AuthenticationIdentityManager. Try upgrading the to latest pre-release version.
In the latest version, you can provide PasswordValidator implementation to UserManager. This will enable customization of password strength validation in your app.
ASP.NET Identity nighlty packages are now available on MyGet
Upvotes: 1