Exemple #1
0
 public void TestGenerateHashIncorrectVersion()
 {
     Assert.Throws <ArgumentOutOfRangeException>(
         delegate { DbaPasswordHash.GenerateHash("password", version: (DbaPasswordHashVersion)7); },
         "Unsupported password version of 7"
         );
 }
Exemple #2
0
        public void TestCaseInsensitiveV2PasswordException()
        {
            var password = "******";

            Assert.Throws <ArgumentException>(
                delegate { DbaPasswordHash.GenerateHash(password, version: DbaPasswordHashVersion.Sql2012, caseInsensitive: true); },
                "Only Sql Server 2000 passwords can be case insensitive."
                );
        }
Exemple #3
0
        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"));
        }
Exemple #4
0
 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.");
     }
 }
Exemple #5
0
        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));
        }
Exemple #6
0
        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()));
        }