Example #1
0
def test_calculate_entropy_normal():
    password = "******"

    entropy = calculate_entropy(password)
    assert entropy == math.log(27**len(password), 2)

    entropy = calculate_entropy(password, method="normal")
    assert entropy == math.log(27**len(password), 2)
Example #2
0
    def __init__(self, password: str, character_pool: CharacterPool = None):
        # set character pool
        if character_pool is None:
            self.pool = CharacterPool()
        else:
            self.pool = character_pool

        assert all(
            i in self.pool.all for i in password
        ), "A password can only use characters from the character_pool provided"

        # set password
        self.password = password

        # set the number of lowercase in the password
        self.lowercase = len([
            character for character in password
            if character in self.pool.lowercase
        ])

        # set the uppercase of lowercase in the password
        self.uppercase = len([
            character for character in password
            if character in self.pool.uppercase
        ])

        # set the symbols of lowercase in the password
        self.symbols = len([
            character for character in password
            if character in self.pool.symbols
        ])

        # set the numbers of lowercase in the password
        self.numbers = len([
            character for character in password
            if character in self.pool.numbers
        ])

        # set the numbers of whitespace in the password
        self.whitespace = len([
            character for character in password
            if character in self.pool.whitespace
        ])

        # set the other of lowercase in the password
        self.other = len([
            character for character in password if character in self.pool.other
        ])

        # set the length of the password
        self.length = len(password)

        # set entropy
        self.entropy = calculate_entropy(password, character_pool=self.pool)
Example #3
0
def test_calculate_entropy_with_unacceptable_characters():
    password = "******"
    with pytest.raises(UnacceptableCharacters):
        calculate_entropy(password)
Example #4
0
def test_calculate_entropy_lenient():
    password = "******"
    entropy = calculate_entropy(password, method="lenient")
    assert entropy == math.log(95**len(password), 2)
Example #5
0
def test_calculate_entropy_strict():
    password = "******"

    entropy = calculate_entropy(password, method="strict")
    assert entropy == math.log(len(set(password))**len(password), 2)