gpt4 book ai didi

asp.net-identity - VerifyHashedPassword 结果何时为 SuccessRehashNeeded

转载 作者:行者123 更新时间:2023-12-01 23:20:22 25 4
gpt4 key购买 nike

Usermanager.VerifyHashedPassword结果何时会是PasswordVerificationResult.SuccessRehashNeeded

出现这样的结果怎么办?

使用VerifyHashedPassword时,我仅使用Success检查它。是否足够,或者我应该用 Failed 检查它?

最佳答案

我在 PasswordHasher.cs 的来源中找到了这个在 github

public virtual PasswordVerificationResult VerifyHashedPassword(TUser user, string hashedPassword, string providedPassword)
{
if (hashedPassword == null)
{
throw new ArgumentNullException(nameof(hashedPassword));
}
if (providedPassword == null)
{
throw new ArgumentNullException(nameof(providedPassword));
}

byte[] decodedHashedPassword = Convert.FromBase64String(hashedPassword);

// read the format marker from the hashed password
if (decodedHashedPassword.Length == 0)
{
return PasswordVerificationResult.Failed;
}
switch (decodedHashedPassword[0])
{
case 0x00:
if (VerifyHashedPasswordV2(decodedHashedPassword, providedPassword))
{
// This is an old password hash format - the caller needs to rehash if we're not running in an older compat mode.
return (_compatibilityMode == PasswordHasherCompatibilityMode.IdentityV3)
? PasswordVerificationResult.SuccessRehashNeeded
: PasswordVerificationResult.Success;
}
else
{
return PasswordVerificationResult.Failed;
}

case 0x01:
int embeddedIterCount;
if (VerifyHashedPasswordV3(decodedHashedPassword, providedPassword, out embeddedIterCount))
{
// If this hasher was configured with a higher iteration count, change the entry now.
return (embeddedIterCount < _iterCount)
? PasswordVerificationResult.SuccessRehashNeeded
: PasswordVerificationResult.Success;
}
else
{
return PasswordVerificationResult.Failed;
}

default:
return PasswordVerificationResult.Failed; // unknown format marker
}
}

似乎 SuccessRehashNeeded 是我们从当前 Identity 版本更改为另一个版本时的结果。

关于asp.net-identity - VerifyHashedPassword 结果何时为 SuccessRehashNeeded,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30251939/

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