如何解决“BCrypt”不包含“验证”的定义
我正在开发一个 ASP.NET Core MVC Web 应用程序。为此,我使用 Identity UI 来处理用户帐户。在身份用户而不是默认散列方法(ASP.NET Identity Version 2: PBKDF2 with HMAC-SHA1,128-bit salt,256-bit subkey,1000 iterations)中,我将修改它并使用自定义散列算法(Bcrypt ) 如下:
(我已经按照 Visual Studio IntelliSense 的建议安装了 NuGet 包 'Portable.BouncyCastle')
BCryptPasswordHasher.cs
using Microsoft.AspNetCore.Identity;
using Org.BouncyCastle.Crypto.Generators;
using System;
using System.Text;
namespace WATERrhythmWeb
{
public class BCryptPasswordHasher<TUser> : PasswordHasher<TUser> where TUser : class
{
readonly BCryptPasswordSettings _settings;
public BCryptPasswordHasher(BCryptPasswordSettings settings)
{
_settings = settings;
}
public override 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;
}
// ASP.NET Core uses 0x00 and 0x01,so we start at the other end
if (decodedHashedPassword[0] == 0xFF)
{
if (VerifyHashedPasswordBcrypt(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 _settings.RehashPasswords
? PasswordVerificationResult.SuccessRehashNeeded
: PasswordVerificationResult.Success;
}
else
{
return PasswordVerificationResult.Failed;
}
}
return base.VerifyHashedPassword(user,hashedPassword,providedPassword);
}
private static bool VerifyHashedPasswordBcrypt(byte[] hashedPassword,string password)
{
if (hashedPassword.Length < 2)
{
return false; // bad size
}
//convert back to string for BCrypt,ignoring first byte
var storedHash = Encoding.UTF8.GetString(hashedPassword,1,hashedPassword.Length - 1);
return BCrypt.Verify(password,storedHash);
}
}
}
方法'private static bool VerifyHashedPasswordBcrypt(byte[] hashedPassword,string password)'
中,return语句有问题。 BCrypt
没有 'Verify'
的定义。我在互联网上搜索试图找到类似的方法。但没有这样做。
严重性代码描述项目文件行抑制状态 错误 CS0117 'BCrypt' 不包含定义 '验证' WATERrhythmWeb D:\Implementations\WebAppAndWebAPI-Recreation\Github014\WATERrhythmWEB-API\WATERrhythmWeb\BCryptPasswordHasher.cs 58 Active
如果有人可以帮助我了解如何纠正上述问题,我将不胜感激。
提前致谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。