Example #1
0
    def is_correct_email_address(self, email_address: str) -> bool:
        """Check if the email address is correct for this user."""
        if not self.email_address_hash:
            raise ValueError("User has not set an email address")

        return is_match_for_hash(email_address.lower(),
                                 self.email_address_hash)
Example #2
0
def test_different_string_fails():
    """Ensure that a different string doesn't match the hash."""
    string = "correct horse battery staple"
    wrong_string = "incorrect horse battery staple"

    hashed = hash_string(string)
    assert not is_match_for_hash(wrong_string, hashed)
Example #3
0
    def is_correct_password(self, password: str) -> bool:
        """Check if the password is correct for this user."""
        # Some accounts have no password - the special-purpose "fake" accounts (ones
        # with user_id <= 0), and it's possible to happen for a real account as well, in
        # a niche case like un-deleting an account that was deleted a long time ago.
        # Trying to check a password on those accounts will error, so just always fail.
        if not self.password_hash:
            return False

        return is_match_for_hash(password, self.password_hash)
Example #4
0
 def is_correct_password(self, password: str) -> bool:
     """Check if the password is correct for this user."""
     return is_match_for_hash(password, self.password_hash)
Example #5
0
def test_same_string_verifies():
    """Ensure that the same string will match the hashed result."""
    string = "hunter2"
    hashed = hash_string(string)
    assert is_match_for_hash(string, hashed)