def password_changed(self, password, user=None): if not self._user_ok(user): return user_config = UserPasswordHistoryConfig.objects.filter( user=user, iterations=get_password_hasher().iterations ).first() if not user_config: user_config = UserPasswordHistoryConfig() user_config.user = user user_config.save() password_hash = user_config.make_password_hash(password) # We are looking hash password in the database try: PasswordHistory.objects.get( user_config=user_config, password=password_hash ) except PasswordHistory.DoesNotExist: ols_password = PasswordHistory() ols_password.user_config = user_config ols_password.password = password_hash ols_password.save() # We make sure there are no old passwords in the database. self.delete_old_passwords(user)
def password_changed(self, password, user=None): if not user: return user_config = UserPasswordHistoryConfig.objects.filter( user=user, iterations=get_password_hasher().iterations ).first() if not user_config: user_config = UserPasswordHistoryConfig() user_config.user = user user_config.save() password_hash = user_config.make_password_hash(password) # We are looking hash password in the database try: PasswordHistory.objects.get( user_config=user_config, password=password_hash ) except PasswordHistory.DoesNotExist: ols_password = PasswordHistory() ols_password.user_config = user_config ols_password.password = password_hash ols_password.save()
def save(self, *args, **kwargs): # When there is no salt as defined for a given user, # then we create the salt. if not self.salt: self._gen_password_history_salt() # We take iterations from the default Hasher if not self.iterations: self.iterations = get_password_hasher().iterations return super(UserPasswordHistoryConfig, self).save(*args, **kwargs)
def make_password_hash(self, password): """ Generates a password hash for the given password. Args: passaword - the password is not encrypted form """ hasher = get_password_hasher()() return hasher.encode(password, self.salt, self.iterations)
def save(self, *args, **kwargs): # When there is no salt as defined for a given user, # then we create the salt. if not self.salt: self._gen_password_history_salt() # We take iterations from the default Hasher if not self.iterations: self.iterations = get_password_hasher().iterations return super(UserPasswordHistoryConfig, self).save(*args, **kwargs)
def make_password_hash(self, password): """ Generates a password hash for the given password. Args: passaword - the password is not encrypted form """ hasher = get_password_hasher()() return hasher.encode(password, self.salt, self.iterations)