def setUp(self): super(TestHostedCCZLinkSerializer, self).setUp() self.link = HostedCCZLink(username="******", domain="test", identifier="abcdef", page_title="page title") self.link.password = hash_password(self.raw_password)
def password_changed(self, password, user): # store password attempt and retain just RESTRICT_USED_PASSWORDS_NUM attempts # Also set expiry time to avoid retaining passwords in redis forever client = get_redis_client() key_name = self.redis_key_for_user(user.username) attempts = client.get(key_name, []) attempts.append(hash_password(password)) client.set(key_name, attempts[-RESTRICT_USED_PASSWORDS_NUM:]) client.expire(key_name, timedelta(EXPIRE_PASSWORD_ATTEMPTS_IN))
def save(self, *args, **kwargs): if not self.pk: self.password = hash_password(self.password) self.full_clean() super(HostedCCZLink, self).save(*args, **kwargs)