mirror of
https://github.com/ACEmulator/ACE
synced 2026-08-17 12:26:06 -04:00
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
30 lines
1 KiB
C#
30 lines
1 KiB
C#
namespace ACE.Common.Cryptography
|
|
{
|
|
public static class BCryptProvider
|
|
{
|
|
public static string HashPassword(string input, int workFactor = 10)
|
|
{
|
|
// 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)
|
|
{
|
|
return BCrypt.Net.BCrypt.Verify(text, hash);
|
|
}
|
|
|
|
public static int GetPasswordWorkFactor(string hash)
|
|
{
|
|
var hashInformation = BCrypt.Net.BCrypt.InterrogateHash(hash);
|
|
|
|
if (int.TryParse(hashInformation.WorkFactor, out var workFactor))
|
|
return workFactor;
|
|
|
|
return 0;
|
|
}
|
|
}
|
|
}
|