Skip to content

Commit

Permalink
Add FAQ about captcha types (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
forgetso authored Feb 6, 2025
1 parent 405e24a commit 652f12e
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 24 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "docs",
"version": "2.3.2",
"version": "2.4.1",
"private": true,
"engines": {
"node": "20",
"npm": "10.8.2"
"npm": ">=9"
},
"scripts": {
"dev": "astro dev",
Expand Down
Binary file added src/assets/image-settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/pow-settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 53 additions & 20 deletions src/content/docs/en/basics/captcha-types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,66 @@ title: CAPTCHA Types
description: Serve different types of CAPTCHA by setting the `captchaType` to `frictionless`, `pow`, `image`.
i18nReady: true
---
import { Image } from 'astro:assets';
import {Image} from 'astro:assets';
import ProcaptchaGIF from '~/assets/procaptcha-pow.gif';
import ImageCaptcha from '~/assets/image-captcha.png';

Procaptcha's default `frictionless` feature dynamically detects if the user is a bot or a human. If the user is likely
to be a bot, the user will be presented with an image CAPTCHA challenge. If the user is likely to be a human, the
user will not be presented with an image CAPTCHA challenge and will instead solve a simple, invisible Proof of Work (PoW) challenge.
import PoWSettings from '~/assets/pow-settings.png';
import ImageSettings from '~/assets/image-settings.png';

Serve **different** types of CAPTCHA by setting the `captchaType` to `frictionless`, `pow`, `image`.

## Frictionless CAPTCHA

Procaptcha's default `frictionless` feature dynamically detects if the user is using a normal browser or automated,
headless browsers such as [playwright](https://playwright.dev/) or [selenium](https://www.selenium.dev/). If the user is
likely to be a bot, the user will be presented with an image CAPTCHA challenge. If the user is likely to be a human, the
user will not be presented with an image CAPTCHA challenge and will instead solve a simple, invisible Proof of Work
(PoW) challenge.

## Proof of Work (PoW) CAPTCHA

A Proof of Work (`pow`) CAPTCHA challenge requires the user to solve a computational puzzle before submitting the form. It is easy for humans to solve but computationally expensive for bots.

<Image src={ProcaptchaGIF} alt={'prosopo procaptcha pow captcha challenge'} style="margin: 20px auto;"/>

The Proof of Work CAPTCHA type does not interrogate the user's browser environment, use `frictionless` for that (above).

## Image CAPTCHA

An image CAPTCHA challenge requires the user to select the correct image(s) that match the given prompt.

<Image
src={ImageCaptcha}
alt="prosopo procaptcha image captcha challenge"
style="margin: 0 auto;"
/>

The Image CAPTCHA type does not interrogate the user's browser environment, use `frictionless` for that (above).

## Set Type Implicitly

### 1. Set the type in the widget configuration

Here we are setting the `captchaType` to Proof-of-Work `pow`.

```html
<div class="procaptcha" data-sitekey="your_site_key" data-captcha-type="frictionless"></div>
<div class="procaptcha" data-sitekey="your_site_key" data-captcha-type="pow"></div>
```

### 2. Set the type in the portal

Navigate to the [Prosopo portal](https://portal.prosopo.io) and update the CAPTCHA type in the settings to `pow`.

<Image
src={PoWSettings}
alt="prosopo pow setting"/>

## Set Type Explicitly

### 1. Set the type in the widget configuration

Here we are setting the `captchaType` to Image `image`.

```javascript
document.getElementById('procaptcha-script').addEventListener('load', function () {
function onCaptchaVerified(output) {
Expand All @@ -32,25 +74,16 @@ document.getElementById('procaptcha-script').addEventListener('load', function (
siteKey: 'YOUR_SITE_KEY',
theme: 'dark',
callback: onCaptchaVerified,
captchaType: 'image', // `pow` or `frictionless`
captchaType: 'image', // `pow` or leave blank for `frictionless`
})
})
```

## Proof of Work (PoW) CAPTCHA
### 2. Set the type in the portal

A Proof of Work (PoW) CAPTCHA challenge requires the user to solve a computational puzzle before submitting the form. It is easy for humans to solve but computationally expensive for bots.

<Image src={ProcaptchaGIF} alt={'prosopo procaptcha pow captcha challenge'} />

The Proof of Work CAPTCHA type does not interrogate the user's browser environment, use `frictionless` for that (above).

## Image CAPTCHA

An image CAPTCHA challenge requires the user to select the correct image(s) that match the given prompt.
Navigate to the [Prosopo portal](https://portal.prosopo.io) and update the CAPTCHA type in the settings to `image`.

<Image
src={ImageCaptcha}
alt="prosopo procaptcha image captcha challenge" />
src={ImageSettings}
alt="prosopo image setting"/>

The Image CAPTCHA type does not interrogate the user's browser environment, use `frictionless` for that (above).
6 changes: 6 additions & 0 deletions src/content/docs/en/basics/faq.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ logging in to the [Prosopo portal](https://portal.prosopo.io) and updating the d
This error will occur if incorrect data has been sent with the captcha response. To resolve this error, ensure that the
data sent with the captcha response is correct.

## What does `Incorrect CAPTCHA type` mean?
This error occurs when the [captcha type](/en/basics/captcha-types) is not set correctly. The default `captchaType` is
`frictionless`. If you wish to use `pow` or `image` you must set your `captchaType` in the widget configuration to `pow`
or `image`. You must also update your [portal settings](https://portal.prosopo.io) to match.


109 changes: 107 additions & 2 deletions src/content/docs/en/basics/server-side-verification.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,115 @@ in the example above. The response will be a JSON object with a `verified` key,
}
```
If you are a [Premium Tier customer](https://prosopo.io/pricing/) then you will also receive a risk score associated
with the request. The closer the score is to 1, the more likely it is that the request is from a bot.
```json
{
"verified": true,
"score": 0.1
}
```
## Verification Code Examples
### JavaScript
<section id="js">
```javascript
const fetch = require('node-fetch');
async function verifyToken(token) {
const response = await fetch('https://api.prosopo.io/siteverify', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({secret: 'your_secret_key', token}),
});
return response.json().verified || false; // Return verified field, default to false
}
```
</section>
### PHP
<section id="php">
```php
<?php
function verifyToken($token) {
$url = 'https://api.prosopo.io/siteverify';
$data = json_encode(["secret" => "your_secret_key", "token" => $token]);
$options = [
'http' => [
'header' => "Content-Type: application/json\r\n",
'method' => 'POST',
'content' => $data,
],
];
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$response = json_decode($result, true);
return $response["verified"] ?? false; // Return verified field, default to false
}
?>
```
</section>
### Python
<section id="python">
```python
import requests
def verify_token(token):
url = "https://api.prosopo.io/siteverify"
data = {"secret": "your_secret_key", "token": token}
response = requests.post(url, json=data)
return response.json().get("verified", False) # Return verified field, default to False
```
</section>
### Java
<section id="java">
```java
import java.io.*;
import java.net.*;
import org.json.JSONObject;
public class ProcaptchaVerification {
public static boolean verifyToken(String token) throws Exception {
URL url = new URL("https://api.prosopo.io/siteverify");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json");
con.setDoOutput(true);
String jsonInputString = "{\"secret\":\"your_secret_key\", \"token\":\"" + token + "\"}";
try (OutputStream os = con.getOutputStream()) {
byte[] input = jsonInputString.getBytes("utf-8");
os.write(input, 0, input.length);
}
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), "utf-8"));
StringBuilder response = new StringBuilder();
String responseLine;
while ((responseLine = br.readLine()) != null) {
response.append(responseLine.trim());
}
// Parse JSON response
JSONObject jsonResponse = new JSONObject(response.toString());
return jsonResponse.optBoolean("verified", false); // Default to false if not found
}
}
```
</section>
## Verification Package
We have a JavaScript implementation of the Procaptcha verification package and we are working on
delivering additional language support.
We have a JavaScript implementation of the Procaptcha verification package [available on npm](https://www.npmjs.com/package/@prosopo/server).
### JavaScript / TypeScript Verification
Expand Down

0 comments on commit 652f12e

Please sign in to comment.