Package org.passay.dictionary
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.- Author:
- Middleware Services
-
-
Constructor Summary
Constructors Constructor Description BloomFilterDictionary(com.google.common.hash.BloomFilter<String> bf)
Creates a new dictionary instance from the suppliedBloomFilter
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description com.google.common.hash.BloomFilter<String>
getBloomFilter()
Returns the bloom filter used for searching.boolean
search(String word)
WARNING bloom filters may return true for a word that is NOT in the dictionary.long
size()
Returns an estimate for the number of words added to the dictionary.String
toString()
-
-
-
Constructor Detail
-
BloomFilterDictionary
public BloomFilterDictionary(com.google.common.hash.BloomFilter<String> bf)
Creates a new dictionary instance from the suppliedBloomFilter
. 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:
bf
- bloom filter used to determine if a word exists.
-
-
Method Detail
-
getBloomFilter
public com.google.common.hash.BloomFilter<String> 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. SeeBloomFilter.approximateElementCount()
.- Specified by:
size
in interfaceDictionary
- Returns:
- approximate number of words in the dictionary
-
search
public boolean search(String 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 andBloomFilter.mightContain(Object)
.- Specified by:
search
in interfaceDictionary
- 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
-
-