diff --git a/csharp-password-hash/csharp-password-hash/Hashing.cs b/csharp-password-hash/csharp-password-hash/Hashing.cs index a71e244..9353743 100644 --- a/csharp-password-hash/csharp-password-hash/Hashing.cs +++ b/csharp-password-hash/csharp-password-hash/Hashing.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Security.Cryptography; using System.Text; +using BCrypt.Net; namespace CSharpPasswordHash { @@ -184,6 +185,11 @@ public static string ToPBKDF2(byte[] plainTextBytes, String salt, EncodingType e } } + private static ToBCRYPT(string password, string salt) + { + return BCrypt.HashPassword(password, salt); + } + public static string HashPassword(string password, string salt, HashingAlgo hashingAlgo, EncodingType encodingType, int pbkdf2Iterations) { @@ -210,6 +216,9 @@ public static string HashPassword(string password, string salt, HashingAlgo hash case HashingAlgo.PBKDF2: return ToPBKDF2(password, salt, encodingType, pbkdf2Iterations); + case HashingAlgo.BCRYPT: + return ToBCRYPT(password, salt); + case HashingAlgo.NONE: return password; @@ -237,6 +246,8 @@ public static bool CheckPassword(string password, string salt, string hash, Hash return ToMd5(password, encodingType) == hash; case HashingAlgo.PBKDF2: return ToPBKDF2(password, salt, encodingType, pbdfk2Iterations) == hash; + case HashingAlgo.BCRYPT: + return ToBCRYPT(password, salt) == hash; case HashingAlgo.NONE: return false; default: diff --git a/csharp-password-hash/csharp-password-hash/HashingAlgo.cs b/csharp-password-hash/csharp-password-hash/HashingAlgo.cs index fe6b899..1f47522 100644 --- a/csharp-password-hash/csharp-password-hash/HashingAlgo.cs +++ b/csharp-password-hash/csharp-password-hash/HashingAlgo.cs @@ -9,6 +9,7 @@ public enum HashingAlgo SHA256 = 4, HMAC_SHA256 = 5, SHA512 = 6, - PBKDF2 = 7 + PBKDF2 = 7, + BCRYPT = 8 } }