

def validate_second_factor(self):
    if (django.VERSION < (1, 9)):
        return self._validate_second_factor_legacy()
    (count, _) = self.user.backup_codes.filter(code=self.cleaned_data['code']).delete()
    if (count == 0):
        self.add_error('code', self.INVALID_ERROR_MESSAGE)
        return False
    elif (count == 1):
        return True
    else:
        assert False, 'Impossible, there should never be more than one object with the same code.'

dataset/ETHPy150Open gavinwahl/django-u2f/django_u2f/forms.py BackupCodeForm.validate_second_factor/original