C# MVC BCrypt.Verify允许使用不同的密码

C# MVC BCrypt.Verify允许使用不同的密码,c#,asp.net-mvc-4,bcrypt,C#,Asp.net Mvc 4,Bcrypt,我不小心输入了错误的密码,它已通过验证。我发现密码是用额外的盐保存的 this.password = BCrypt.Net.BCrypt.HashPassword(prefixSalt + password + suffixSalt, BCrypt.Net.BCrypt.GenerateSalt(9)); 核查: BCrypt.Net.BCrypt.Verify(prefixSalt + password + suffixSalt, this.password); 这样,密码被截断为8个字符

我不小心输入了错误的密码,它已通过验证。我发现密码是用额外的盐保存的

this.password = BCrypt.Net.BCrypt.HashPassword(prefixSalt + password + suffixSalt, BCrypt.Net.BCrypt.GenerateSalt(9));
核查:

BCrypt.Net.BCrypt.Verify(prefixSalt + password + suffixSalt, this.password);

这样,密码被截断为8个字符,第8个字符之后的任何内容都将被忽略。是否可以在不要求所有用户更改密码的情况下修复此问题

bcrypt的过程无法逆转,它是一种单向算法。您可以通过以下过程“修复”数据:

if (BCrypt.Verify(password, storedHash)) {
    // Log on user
} else if (BCrypt.Verify(prefixSalt + password + suffixSalt, storedHash)) {
    this.password = BCrypt.HashPassword(password);
    // Save to database
    // Log on user
} else {
    // User details incorrect
}
但是,如果密码被截断(虽然我不明白为什么会被截断-可能错误在代码的其他地方?),这将不起作用,因为它最初允许任何人设置其他人的密码


简短回答:,您需要重置每个人的密码。

为什么您认为密码被截断为8个字符?我不知道为什么。我测试没有前缀和后缀,工作很好。。。但这不是我的问题。我只是想避免更改密码。