def validate_second_factor(self):
        response = json.loads(self.cleaned_data['response'])
        try:
            # find the right challenge, the based on the key the user inserted
            challenge = [c for c in self.challenges if c['keyHandle'] == response['keyHandle']][0]
            device = self.user.u2f_keys.get(key_handle=response['keyHandle'])
            login_counter, touch_asserted = u2f.verify_authenticate(
                device.to_json(),
                challenge,
                response,
            )
            # TODO: store login_counter and verify it's increasing
            device.last_used_at = timezone.now()
            device.save()
            del self.request.session['u2f_authentication_challenges']
            return True
        except InvalidSignature:
            self.add_error('__all__', 'U2F validation failed -- bad signature.')
        return False
dataset/ETHPy150Open gavinwahl/django-u2f/django_u2f/forms.py/KeyResponseForm.validate_second_factor/original