public void TestCaseInsensitivePasswordPasswordHash() { var password = "******"; var hash = DbaPasswordHash.GenerateHash(password, version: DbaPasswordHashVersion.Sql2000, caseInsensitive: true); Assert.AreEqual(DbaPasswordHash.Sha1CaseInsensitivePasswordHashLength, hash.Length); var hashObj = new DbaPasswordHash(hash); Assert.True(hashObj.VerifyPassword(password)); Assert.True(hashObj.VerifyPassword(password.ToLower())); Assert.True(hashObj.VerifyPassword(password.ToLowerInvariant())); Assert.True(hashObj.VerifyPassword(password.ToUpper())); Assert.True(hashObj.VerifyPassword(password.ToUpperInvariant())); }
public void TestHashVerifyFail() { var password = Passwords[0]; var hashBytes = HexadecimalStringToByteArray_BestEffort(password.Hash); var passwordHash = new DbaPasswordHash(hashBytes); var generatedHash = DbaPasswordHash.GenerateHash("Not the password", passwordHash.Salt); Assert.AreNotEqual(hashBytes, generatedHash); Assert.False(passwordHash.VerifyPassword("Not the Password")); }
public void TestHashVerify() { foreach (var password in Passwords) { var hashBytes = HexadecimalStringToByteArray_BestEffort(password.Hash); var passwordHash = new DbaPasswordHash(hashBytes); var generatedHash = DbaPasswordHash.GenerateHash(password.PlainText, passwordHash.Salt, passwordHash.HashVersion, passwordHash.RawHashUpperCase != null); Assert.AreEqual(hashBytes, generatedHash, $"Password hash for {password.PlainText} is incorrect."); Assert.True(passwordHash.VerifyPassword(password.PlainText), $"Verifying password {password.PlainText} against hash failed."); } }
public void TestPassworWithRandomHash() { var password = "******"; var passwordHash = DbaPasswordHash.GenerateHash(password); var passwordHash2000 = DbaPasswordHash.GenerateHash(password, version: DbaPasswordHashVersion.Sql2000); Assert.AreNotEqual(passwordHash2000, passwordHash); var hashObj = new DbaPasswordHash(passwordHash); var hashObj2000 = new DbaPasswordHash(passwordHash2000); Assert.True(hashObj.VerifyPassword(password)); Assert.True(hashObj2000.VerifyPassword(password)); }