Class BloomFilterDictionary

java.lang.Object
org.passay.dictionary.BloomFilterDictionary
All Implemented Interfaces:
Dictionary

public class BloomFilterDictionary extends Object implements Dictionary
Dictionary that is backed by a Bloom Filter. WARNING bloom filters may return true for a word that is NOT in the dictionary. This implementation should only be used if false positives can be tolerated.
  • Field Details

    • bloomFilter

      private final com.google.common.hash.BloomFilter<CharSequence> bloomFilter
      Filter used for searching.
  • Constructor Details

    • BloomFilterDictionary

      public BloomFilterDictionary(com.google.common.hash.BloomFilter<CharSequence> filter)
      Creates a new dictionary instance from the supplied BloomFilter. The fpp (false-positive probability) parameter of the given Bloom filter is a vitally important configuration concern. If it is too high, one risks user frustration due to rejection of valid passwords; if it is too low, one risks excessive storage costs. Finding the proper balance between acceptable user experience and storage costs is worth the time and effort required in testing. The Guava default value of 3% is likely unsuitable for many if not most deployments.
      Parameters:
      filter - bloom filter used to determine if a word exists.
  • Method Details

    • getBloomFilter

      public com.google.common.hash.BloomFilter<CharSequence> getBloomFilter()
      Returns the bloom filter used for searching.
      Returns:
      bloom filter
    • size

      public long size()
      Returns an estimate for the number of words added to the dictionary. See BloomFilter.approximateElementCount().
      Specified by:
      size in interface Dictionary
      Returns:
      approximate number of words in the dictionary
    • search

      public boolean search(CharSequence word)
      WARNING bloom filters may return true for a word that is NOT in the dictionary. Please make sure you understand how bloom filters work before using this implementation. @see Bloom Filter and BloomFilter.mightContain(Object).
      Specified by:
      search in interface Dictionary
      Parameters:
      word - to search for
      Returns:
      true if the word might be in the bloom filter, false if the word is definitely not in the bloom filter
    • toString

      public String toString()
      Overrides:
      toString in class Object