Exemplo n.º 1
0
    def test_salt(self):
        """
        Tests that password hashes are salted
        :return: None
        """
        password = generate_random(30)
        hash_one = generate_hash(password)
        hash_two = generate_hash(password)

        self.assertNotEqual(hash_one, hash_two)

        self.assertTrue(verify_password(password, hash_one))
        self.assertTrue(verify_password(password, hash_two))
Exemplo n.º 2
0
 def test_verifying_with_invalid_hash(self):
     """
     Tests that attempting to verify a password with an incorrectly
     formatted hash will return False
     :return: None
     """
     self.assertFalse(verify_password("A", "A"))
Exemplo n.º 3
0
 def verify_confirmation(self, confirmation_key: str) -> bool:
     """
     Verifies a confirmation key against the confirmation hash
     :param confirmation_key: The key to check
     :return: True if the key matches, False otherwise
     """
     return verify_password(confirmation_key, self.confirmation_hash)
Exemplo n.º 4
0
 def verify_password(self, password: str) -> bool:
     """
     Verifies a password against the password hash
     :param password: The password to check
     :return: True if the password matches, False otherwise
     """
     return verify_password(password, self.password_hash)
Exemplo n.º 5
0
 def test_hashing_strings(self):
     """
     Tests that password hashing and verifying works with string as well
     :return: None
     """
     password = str(generate_random(30))
     _hash = generate_hash(password)
     self.assertTrue(verify_password(password, _hash))
Exemplo n.º 6
0
    def test_hashing(self):
        """
        Tests that passwords can be hashed successfully
        :return: None
        """
        password_one = generate_random(30)
        password_two = generate_random(20)

        hash_one = generate_hash(password_one)
        hash_two = generate_hash(password_two)

        self.assertEqual(len(hash_one), len(hash_two))
        self.assertNotEqual(hash_one, hash_two)

        self.assertTrue(verify_password(password_one, hash_one))
        self.assertTrue(verify_password(password_two, hash_two))
        self.assertFalse(verify_password(password_one, hash_two))
        self.assertFalse(verify_password(password_two, hash_one))
Exemplo n.º 7
0
 def verify_key(self, key: str) -> bool:
     """
     Checks if a given key is valid
     :param key: The key to check
     :return: True if the key is valid, False otherwise
     """
     try:
         _id, api_key = key.split(":", 1)
         if int(_id) != self.id:
             return False
         else:
             return verify_password(api_key, self.key_hash)
     except ValueError:
         return False