Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Bycrpt Algo fix #26 #32

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions csharp-password-hash/csharp-password-hash/Hashing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using BCrypt.Net;

namespace CSharpPasswordHash
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -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;

Expand Down Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion csharp-password-hash/csharp-password-hash/HashingAlgo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public enum HashingAlgo
SHA256 = 4,
HMAC_SHA256 = 5,
SHA512 = 6,
PBKDF2 = 7
PBKDF2 = 7,
BCRYPT = 8
}
}