PasswordHasherCompatibilityMode

PasswordHasherCompatibilityMode

本文介绍了如何在ASP.NET 5 Identity中设置PasswordHasherCompatibilityMode.IdentityV3?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前看来,默认值设置为PasswordHasherCompatibilityMode.IdentityV2,它是ASP.NET 5中的HMAC-SHA1.我试图创建PasswordHasherOptions的实例以添加到服务(DI)中,但无法使其正常工作./p>

V3将PBKDF2与HMAC-SHA256、128位盐,256位子项,10000次迭代一起使用.

我希望这将与将来的某些配置设置一样简单,而不必执行自定义实现,因为所有代码都已经存在.

更新:

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

解决方案

默认值不应为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.

Currently it seems default is set to PasswordHasherCompatibilityMode.IdentityV2 which is HMAC-SHA1 in ASP.NET 5. I tried to create a instance of PasswordHasherOptions to add to services (DI) but could not get it to work.

V3 uses PBKDF2 with HMAC-SHA256, 128-bit salt, 256-bit subkey, 10000 iterations.

I hope this would be as easy as some configuration setting in future rather than having to implement custom implementation since all the code is already there.

Update:

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

解决方案

The default shouldn't be V2, the default is the newer format, as you can see in 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;

If the first byte of the hashed password is 0x01 then it's a version 3 hash.

If you're seeing 0x00 then either it's configured elsewhere in your code, or there's a bug, in which case please log it on GitHub.

这篇关于如何在ASP.NET 5 Identity中设置PasswordHasherCompatibilityMode.IdentityV3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 22:58