public void SortedFileSearcher_FileInput() { string hashesFile = Path.GetTempFileName(); try { File.WriteAllText(hashesFile, PwnedPasswordHashesOrderedByHash); using (var searcher = new SortedFileSearcher(hashesFile)) { // Find first Assert.IsTrue(searcher.FindString("1AE188AB6DF35626E09C77F2880CAD75")); // Find last Assert.IsTrue(searcher.FindString("1AE189A6FFF7DB51548F12F063491E36")); // Find middle Assert.IsTrue(searcher.FindString("1AE188FF3AF08946C275C9A7E2B894F2")); // Find non-existing (before first) Assert.IsFalse(searcher.FindString("0AE188AB6DF35626E09C77F2880CAD75")); // Find non-existing (in the middle) Assert.IsFalse(searcher.FindString("1AE188FF3AF08946C275C9A7E2B894F1")); // Find non-existing (after last) Assert.IsFalse(searcher.FindString("F7EB9C06FAFAA23C4BCF22BA6781C1E2")); } } finally { File.Delete(hashesFile); } }
protected virtual void Dispose(bool disposing) { if (disposing && this.sortedHashFileSearcher != null) { this.sortedHashFileSearcher.Dispose(); this.sortedHashFileSearcher = null; } }
public void SortedFileSearcher_StreamInput_Empty() { byte[] input = new byte[0]; using (var stream = new MemoryStream(input)) { using (var searcher = new SortedFileSearcher(stream)) { bool result = searcher.FindString("F7EB9C06FAFAA23C4BCF22BA6781C1E2"); Assert.IsFalse(result); } } }
public void SortedFileSearcher_StreamInput_SingleLine() { byte[] binaryInput = Encoding.ASCII.GetBytes("Gamma"); using (var stream = new MemoryStream(binaryInput)) { using (var searcher = new SortedFileSearcher(stream)) { Assert.IsTrue(searcher.FindString("Gamma")); Assert.IsFalse(searcher.FindString("Alpha")); Assert.IsFalse(searcher.FindString("Omega")); } } }
public void SortedFileSearcher_StreamInput_UnsortedHashes() { // We just need to test that this does not end with an endless loop byte[] binaryInput = Encoding.ASCII.GetBytes(PwnedPasswordHashesOrderedByCount); using (var stream = new MemoryStream(binaryInput)) { using (var searcher = new SortedFileSearcher(stream)) { searcher.FindString("1AE188AB6DF35626E09C77F2880CAD75"); searcher.FindString("69CBE3ACBC48A3A289E8CDB000C2B7A8"); searcher.FindString("1AE188FF3AF08946C275C9A7E2B894F2"); searcher.FindString("F7EB9C06FAFAA23C4BCF22BA6781C1E2"); } } }
public void SortedFileSearcher_StreamInput_SortedHashes() { byte[] binaryInput = Encoding.ASCII.GetBytes(PwnedPasswordHashesOrderedByHash); using (var stream = new MemoryStream(binaryInput)) { var searcher = new SortedFileSearcher(stream); // Find first Assert.IsTrue(searcher.FindString("1AE188AB6DF35626E09C77F2880CAD75")); // Find last Assert.IsTrue(searcher.FindString("1AE189A6FFF7DB51548F12F063491E36")); // Find middle Assert.IsTrue(searcher.FindString("1AE188FF3AF08946C275C9A7E2B894F2")); // Find non-existing Assert.IsFalse(searcher.FindString("F7EB9C06FAFAA23C4BCF22BA6781C1E2")); } }
protected override void EndProcessing() { // Close any open files (we can do it sooner than during dispose) if (this.sortedHashFileSearcher != null) { this.sortedHashFileSearcher.Dispose(); this.sortedHashFileSearcher = null; } // Process duplicate passwords if (!this.SkipDuplicatePasswordTest.IsPresent) { this.result.DuplicatePasswordGroups = this.hashToAccountMap.Values.Where(set => set.Count > 1).ToList(); } // Process Weak Passwords this.TestWeakPasswordsInMemory(); // The processing has finished, so return the results. this.WriteObject(this.result); }
protected override void BeginProcessing() { // Test the optional file path in advance to throw an early error. this.ResolveFilePath(this.WeakPasswordHashesFile); this.ResolveFilePath(this.WeakPasswordsFile); // Open the sorted weak password hashes file, as we will be searching it on-the-fly. string sortedHashesFile = this.ResolveFilePath(this.WeakPasswordHashesSortedFile); if (sortedHashesFile != null) { this.sortedHashFileSearcher = new SortedFileSearcher(sortedHashesFile); } if (this.ShouldTestWeakPasswordsInMemory || !this.SkipDuplicatePasswordTest.IsPresent) { // We need to cache NT hashes of all accounts for the Duplicate and Weak Password Tests. this.hashToAccountMap = new Dictionary <byte[], SortedSet <string> >(PasswordDictionaryInitialCapacity, HashEqualityComparer.GetInstance()); } // Initialize the test results. this.result = new PasswordQualityTestResult(); }
public void SortedFileSearcher_StreamInput_Words() { byte[] binaryInput = Encoding.ASCII.GetBytes(PhoneticAlphabet); using (var stream = new MemoryStream(binaryInput)) { var searcher = new SortedFileSearcher(stream); // Check that we can find all the words that are contained in the input string[] words = PhoneticAlphabet.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); foreach (string word in words) { Assert.IsTrue(searcher.FindString(word)); } // Test some non-existing words Assert.IsFalse(searcher.FindString("AAAA")); Assert.IsFalse(searcher.FindString("ZZZZ")); string[] letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".Split(); foreach (string letter in letters) { Assert.IsFalse(searcher.FindString(letter)); } } }
public void SortedFileSearcher_StreamInput_Null() { var searcher = new SortedFileSearcher((Stream)null); }