【问题标题】:How to configure PasswordHasher<T>?如何配置 PasswordHasher<T>?
【发布时间】:2020-03-14 18:51:21
【问题描述】:

不明白如何使用IOptions接口配置PasswordHasher

这不成立:

var passwordHasher = new PasswordHasher<User>(new PasswordHasherOptions() { CompatibilityMode = PasswordHasherCompatibilityMode.IdentityV2 });

【问题讨论】:

  • 如果您将添加构建完整错误会有所帮助

标签: c# asp.net-core .net-core azure-functions


【解决方案1】:

基本上你不会返回它期望的相同类型。

这是一个典型的例子

public void ConfigureServices(IServiceCollection services)
{
    services.Configure<PasswordHasherOptions>(opt =>
    {
        opt.CompatibilityMode = PasswordHasherCompatibilityMode.IdentityV2;
    });

    // Rest of ConfigureServices here
}

对于 Azure 函数

public class Startup : FunctionsStartup
{
    public override void Configure(IFunctionsHostBuilder builder)
    {
        builder.Services.Configure<PasswordHasherOptions>(opt =>
        {
            opt.CompatibilityMode = PasswordHasherCompatibilityMode.IdentityV2;
        });

        // Rest of Configure here
    }
}

【讨论】:

  • 我在 azure 函数中单独使用它来验证存储在 v2 版本数据库中的旧密码。我怎样才能得到这个 IServiceCollection?
  • 几乎一样,我已经编辑了答案,但是代码没有经过测试
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-11
相关资源
最近更新 更多