Skip to content

Commit

Permalink
Switch from BCrypt.Net-Core to BCrypt.Net-Next (#4083)
Browse files Browse the repository at this point in the history
BCrypt.Net-Core was a 3rd party release to port BCrypt.Net to .NET Core in the early days of .NET Core.

BCrypt.Net-Next is the current standard for BCrypt.Net
https://github.com/BcryptNet/bcrypt.net
  • Loading branch information
Mag-nus authored Jan 8, 2024
1 parent c198abc commit 9768567
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Source/ACE.Common/ACE.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BCrypt.Net-Core" Version="1.6.0" />
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
<PackageReference Include="System.Text.Json" Version="6.0.9" />
<PackageReference Include="TimeZoneConverter" Version="6.1.0" />
</ItemGroup>
Expand Down
14 changes: 12 additions & 2 deletions Source/ACE.Common/Cryptography/BCryptProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ public static class BCryptProvider
{
public static string HashPassword(string input, int workFactor = 10)
{
return BCrypt.Net.BCrypt.HashPassword(input, workFactor, BCrypt.Net.SaltRevision.Revision2Y);
// Force BCrypt.Net-Next to use 2y instead of the default 2a
// The older bcrypt package ACE used (BCrypt.Net-Core) defaultd to 2y
// Reference: https://stackoverflow.com/questions/49878948/hashing-password-with-2y-identifier/75114685
string salt = BCrypt.Net.BCrypt.GenerateSalt(workFactor, 'y');

return BCrypt.Net.BCrypt.HashPassword(input, salt);
}

public static bool Verify(string text, string hash)
Expand All @@ -14,7 +19,12 @@ public static bool Verify(string text, string hash)

public static int GetPasswordWorkFactor(string hash)
{
return BCrypt.Net.BCrypt.GetPasswordWorkFactor(hash);
var hashInformation = BCrypt.Net.BCrypt.InterrogateHash(hash);

if (int.TryParse(hashInformation.WorkFactor, out var workFactor))
return workFactor;

return 0;
}
}
}

0 comments on commit 9768567

Please sign in to comment.