C# 暂时禁用密码要求

C# 暂时禁用密码要求,c#,owin,asp.net-identity-2,C#,Owin,Asp.net Identity 2,我正在将用户帐户迁移到密码至少需要6个字符的应用程序 如果我运行以下函数 var result = await UserManager.CreateAsync(newUser, ""); 它当然会抱怨密码无效。 是否有一种方法可以暂时忽略密码要求,以便创建我的用户 注意事项: private ApplicationUserManager _userManager; public ApplicationUserManager UserManager { get

我正在将用户帐户迁移到密码至少需要6个字符的应用程序

如果我运行以下函数

var result = await UserManager.CreateAsync(newUser, "");
它当然会抱怨密码无效。 是否有一种方法可以暂时忽略密码要求,以便创建我的用户

注意事项:

private ApplicationUserManager _userManager;
    public ApplicationUserManager UserManager
    {
        get
        {
            if (_userManager == null)
            {
                this._userManager = HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
            }
            return _userManager;
        }
        private set
        {
            _userManager = value;
        }
    }
正如它所说,“您的密码长度必须至少为-1个字符”

谢谢@trailmax

啊,这似乎做得很好

this._userManager.PasswordValidator = new CustomPasswordValidator();
还有验证器

public class CustomPasswordValidator : IIdentityValidator<string>
{
    public CustomPasswordValidator()
    {
    }

    public Task<IdentityResult> ValidateAsync(string item)
    {
        return Task.FromResult(IdentityResult.Success);
    }
}
公共类CustomPasswordValidator:IIdentityValidator
{
公共CustomPasswordValidator()
{
}
公共任务ValidateAsync(字符串项)
{
返回Task.FromResult(IdentityResult.Success);
}
}

使用IdentityServer4有一个
IList
验证程序。我必须禁用临时功能,所以我做到了:

var pwValidators = userManager.PasswordValidators.ToList();
userManager.PasswordValidators.Clear(); 

addPaswordResult = await userManager.AddPasswordAsync(user, password);

pwValidators.ForEach(x => userManager.PasswordValidators.Add(x));

实现您自己的密码验证程序?
var pwValidators = userManager.PasswordValidators.ToList();
userManager.PasswordValidators.Clear(); 

addPaswordResult = await userManager.AddPasswordAsync(user, password);

pwValidators.ForEach(x => userManager.PasswordValidators.Add(x));