Exemplo n.º 1
0
    def test_it_encodes_the_salt_correctly(self, salt, expected_salt,
                                           pbkdf2_hmac):
        _, returned_salt = hash_password(sentinel.password, salt)

        pbkdf2_hmac.assert_called_once_with(Any(), Any(), expected_salt, Any())

        assert returned_salt == expected_salt
Exemplo n.º 2
0
    def test_it_generates_hash_as_expected(self):
        # Runs a real test without mocking pbkdf2_hmac. After this we mock
        # as aren't here to check pbkdf2_hmac works and it's very slow
        actual_hash, _ = hash_password("asdf", "fbe82ee0da72b77b")

        assert (
            actual_hash ==
            "e46df2a5b4d50e259b5154b190529483a5f8b7aaaa22a50447e377d33792577a".
            encode("utf8"))
Exemplo n.º 3
0
    def test_it_generates_random_salt_with_no_salt(self):
        _, salt_1 = hash_password(sentinel.password)
        _, salt_2 = hash_password(sentinel.password)

        assert salt_1
        assert salt_1 != salt_2
Exemplo n.º 4
0
    def test_it_encodes_the_password_correctly(self, password,
                                               expected_password, pbkdf2_hmac):
        hash_password(password, sentinel.salt)

        pbkdf2_hmac.assert_called_once_with(Any(), expected_password, Any(),
                                            Any())
Exemplo n.º 5
0
    def test_it_runs_pbkdf2_hmac_with_expected_settings(self, pbkdf2_hmac):
        hash_password(sentinel.password, sentinel.salt)

        pbkdf2_hmac.assert_called_once_with("sha256", Any(), Any(), 1_000_000)
Exemplo n.º 6
0
#!/usr/bin/env python3
from lms.authentication.password_hash import hash_password

if __name__ == "__main__":
    # pylint: disable=invalid-name
    password = input("Please enter a password: "******"utf8")
    salt = input("Please enter a salt (leave blank to have one created): ")

    pw_hash, salt = hash_password(password, salt)

    print(f"password hash: {pw_hash}")
    print(f"salt: {salt}")