/// <summary> /// The password is hashed with BCrypt using the format in OpenBSD /// with a cost factor of 12 and a random salt /// </summary> /// <param name="pwd">The password</param> /// <returns>Hash password</returns> public static string GenerateBcryptHash(string pwd) { var passwordCharArray = pwd.ToCharArray(); var salt = new byte[16]; new SecureRandom().NextBytes(salt); return(OpenBsdBCrypt.Generate(passwordCharArray, salt, 12)); }
public override void PerformTest() { string encoded, password; for (int i = 0; i < BCryptTest1.Length; i++) { string[] testString = BCryptTest1[i]; encoded = testString[0]; password = testString[1]; if (!OpenBsdBCrypt.CheckPassword(encoded, password.ToCharArray())) { Fail("test1 mismatch: " + "[" + i + "] " + password); } } encoded = BCryptTest2[0]; password = BCryptTest2[1]; if (!OpenBsdBCrypt.CheckPassword(encoded, password.ToCharArray())) { Fail("bcryptTest2 mismatch: " + password); } encoded = BCryptTest2b[0]; password = BCryptTest2b[1]; if (!OpenBsdBCrypt.CheckPassword(encoded, password.ToCharArray())) { Fail("bcryptTest2b mismatch: " + password); } for (int i = 0; i < BCryptTest3.Length; i++) { string[] testString = BCryptTest3[i]; encoded = testString[2]; password = testString[0]; if (!OpenBsdBCrypt.CheckPassword(encoded, password.ToCharArray())) { Fail("test3 mismatch: " + "[" + i + "] " + password); } } for (int i = 0; i < BCryptTest4.Length; i++) { string[] testString = BCryptTest4[i]; encoded = testString[1]; password = testString[0]; if (!OpenBsdBCrypt.CheckPassword(encoded, password.ToCharArray())) { Fail("test4 mismatch: " + "[" + i + "] " + password); } } }
public override void PerformTest() { string encoded, password; for (int i = 0; i < BCryptTest1.Length; i++) { string[] testString = BCryptTest1[i]; encoded = testString[0]; password = testString[1]; if (!OpenBsdBCrypt.CheckPassword(encoded, password.ToCharArray())) { Fail("test1 mismatch: " + "[" + i + "] " + password); } } encoded = BCryptTest2[0]; password = BCryptTest2[1]; if (!OpenBsdBCrypt.CheckPassword(encoded, password.ToCharArray())) { Fail("bcryptTest2 mismatch: " + password); } encoded = BCryptTest2b[0]; password = BCryptTest2b[1]; if (!OpenBsdBCrypt.CheckPassword(encoded, password.ToCharArray())) { Fail("bcryptTest2b mismatch: " + password); } for (int i = 0; i < BCryptTest3.Length; i++) { string[] testString = BCryptTest3[i]; encoded = testString[2]; password = testString[0]; if (!OpenBsdBCrypt.CheckPassword(encoded, password.ToCharArray())) { Fail("test3 mismatch: " + "[" + i + "] " + password); } } for (int i = 0; i < BCryptTest4.Length; i++) { string[] testString = BCryptTest4[i]; encoded = testString[1]; password = testString[0]; if (!OpenBsdBCrypt.CheckPassword(encoded, password.ToCharArray())) { Fail("test4 mismatch: " + "[" + i + "] " + password); } } { int lower = twoYVec.GetLowerBound(0); int upper = twoYVec.GetUpperBound(0); for (int i = lower; i <= upper; i++) { password = twoYVec[i, 0]; encoded = twoYVec[i, 1]; if (!OpenBsdBCrypt.CheckPassword(encoded, password.ToCharArray())) { Fail("twoYVec mismatch: " + "[" + i + "] " + password); } } } { int lower = twoBVec.GetLowerBound(0); int upper = twoBVec.GetUpperBound(0); for (int i = lower; i <= upper; i++) { password = twoBVec[i, 0]; encoded = twoBVec[i, 1]; if (!OpenBsdBCrypt.CheckPassword(encoded, password.ToCharArray())) { Fail("twoBVec mismatch: " + "[" + i + "] " + password); } } } }