def change_username(self, **kwargs):
        from django.contrib.auth import authenticate as auth_authenticate

        if 'password' not in self.initial_data:
            raise ValidationError("Current password needs to be provided")
        if 'username' not in self.initial_data:
            raise ValidationError("New username needs to be provided")

        user = auth_authenticate(username=self.instance.username, password=self.initial_data['password'])

        if user is not None:
            self.instance.username = self.initial_data['username']
            self.instance.save()
        else:
            raise ValidationError("Username or password is incorrect.")
dataset/ETHPy150Open crowdresearch/crowdsource-platform/crowdsourcing/serializers/user.py/UserSerializer.change_username/original