Example #1
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 #2
0
    def email_address(self, value: Optional[str]) -> None:
        """Set the user's email address (will be stored hashed)."""
        if not value:
            self.email_address_hash = None
            return

        # convert the address to lowercase to avoid potential casing issues
        value = value.lower()
        self.email_address_hash = hash_string(value)
Example #3
0
    def password(self, value: str) -> None:
        # need to do manual validation since some password checks depend on checking the
        # username at the same time (for similarity)
        self.schema.validate({"username": self.username, "password": value})

        self.password_hash = hash_string(value)
Example #4
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)