此自动生成的代码注册了一个新用户:
var manager = new AuthenticationIdentityManager(new IdentityStore());
User u = new User(userName) { UserName = userName };
IdentityResult result = manager.Users.CreateLocalUser(u, Password.Text);
if (result.Success)
{ ... }
我们如何更改密码验证设置?
这是我使用 dotPeek 发现的:
AuthenticationIdentityManager 类实例包含 UserManager,它使用 PasswordValidator 验证密码:
来自 Microsoft.AspNet.Identity.UserManager 类:
result = this.PasswordValidator.Validate(password);
internal IStringValidator PasswordValidator
{
get
{
return this.Manager.Settings.GetIdentityOptions().PasswordValidator;
}
}
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;
}
}
我找不到可以访问或替换 IdentityOptions 实例的位置。有没有示例或文档?