gpt4 book ai didi

c# - 暂时禁用密码要求

转载 作者:行者123 更新时间:2023-11-30 14:53:13 25 4
gpt4 key购买 nike

我正在将用户帐户迁移到密码至少需要 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;
}
}

不幸的是,这不起作用:

this._userManager.PasswordValidator = new PasswordValidator
{
RequiredLength = -1, // I've also tried 0
RequireNonLetterOrDigit = false,
RequireDigit = false,
RequireLowercase = false,
RequireUppercase = false,
};

因为它指出“您的密码长度必须至少为 -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);
}
}

关于c# - 暂时禁用密码要求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29968582/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com