【问题标题】:How to set PasswordHasherCompatibilityMode.IdentityV3 in ASP.NET 5 Identity?如何在 ASP.NET 5 Identity 中设置 PasswordHasherCompatibilityMode.IdentityV3?
【发布时间】:2016-07-23 12:53:08
【问题描述】:

目前似乎默认设置为PasswordHasherCompatibilityMode.IdentityV2,这是 ASP.NET 5 中的 HMAC-SHA1。我尝试创建PasswordHasherOptions 的实例以添加到服务 (DI),但无法使其工作。

V3 使用 PBKDF2 和 HMAC-SHA256、128 位盐、256 位子密钥、10000 次迭代。

我希望这会像将来的一些配置设置一样简单,而不是必须实现自定义实现,因为所有代码都已经存在。

更新:

services.Configure<PasswordHasherOptions>(options => options.CompatibilityMode = PasswordHasherCompatibilityMode.IdentityV3);

【问题讨论】:

  • 您是如何尝试注册PasswordHasherOptions 的。介意发布您的 ConfigureConfigureServices 方法吗?

标签: c# asp.net-core asp.net-identity-3


【解决方案1】:

默认不应该是V2,默认是较新的格式,见https://github.com/aspnet/Identity/blob/dev/src/Microsoft.AspNetCore.Identity/PasswordHasherOptions.cs

    /// <remarks>
    /// The default compatibility mode is 'ASP.NET Identity version 3'.
    /// </remarks>
    public PasswordHasherCompatibilityMode CompatibilityMode { get; set; } = 
           PasswordHasherCompatibilityMode.IdentityV3;

如果散列密码的第一个字节是 0x01,那么它是版本 3 散列。

如果您看到 0x00,则说明它是在您的代码中的其他位置配置的,或者存在错误,在这种情况下,请将其记录在 GitHub 上。

【讨论】:

  • 谢谢,好像是这样。我会检查并回来。
  • 对不起,我还不知道如何确认它是否实际上是 V3,我试图在 Startup.ConfigureServices 中将模式设置为 PasswordHasherCompatibilityMode.IdentityV2 但它仍在生成相同长度的哈希,有什么指点吗?
  • 除非你能告诉我你使用的是哪个版本的身份,否则我在这里能做的并不多。每个存储密码的第一个字节是什么?
  • 附加问题 - 您期望的尺寸是多少? v3 的格式是 Format: { 0x01, prf (UInt32), iter count (UInt32), salt length (UInt32), salt, subkey }。每个 UInt32 为 4 个字节。那么存储密码中的实际盐长度是多少?
猜你喜欢
  • 2014-04-30
  • 1970-01-01
  • 2020-05-08
  • 2015-11-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-24
相关资源
最近更新 更多