def METHOD_NAME(self, value):
    if value is None:
        return
    if not isinstance(value, Password):
        # Hash the password using the default scheme.
        value = self._hash(value).encode('utf8')
        return Password(value, context=self.context)
    else:
        # If were given a password object; ensure the context is right.
        value.context = weakref.proxy(self.context)
        # If were given a password secret; hash it.
        if value.secret is not None:
            value.hash = self._hash(value.secret).encode('utf8')
            value.secret = None
    return value