Example #1
0
    def claim_wpm_challenge(user, token, typed, claimed_wpm):
        challenge_user, reference, start_time = decode_challenge(token=token)
        end_time = time.time()

        if user != challenge_user:
            return

        accuracy = cats.accuracy(" ".join(typed), " ".join(reference))
        wpm = cats.wpm(" ".join(reference), end_time - start_time)

        if wpm < claimed_wpm * CAPTCHA_SLOWDOWN_FACTOR:
            # too slow!
            return {
                "success": False,
                "message": "Your captcha was typed too slowly!"
            }

        if accuracy < CAPTCHA_ACCURACY_THRESHOLD:
            # too inaccurate!
            return {"success": False, "message": "You made too many mistakes!"}

        return {
            "success": True,
            "token": create_wpm_authorization(user, claimed_wpm)
        }
Example #2
0
def analyze(prompted_text, typed_text, start_time, end_time):
    """Return [wpm, accuracy]."""
    return {
        "wpm": cats.wpm(typed_text, end_time - start_time),
        "accuracy": cats.accuracy(typed_text, prompted_text)
    }