Skip to content

Migrate from hCaptcha

The following tutorial will guide you on how to migrate from hCaptcha to TrustCaptcha on your website.

You should have already completed the following steps before you start to integrate TrustCaptcha into your website.

  1. Read Get-Started: Get a quick overview of the concepts behind TrustCaptcha and the integration process in get started.

  2. Existing CAPTCHA: If you don’t have a CAPTCHA yet, sign in or create a new user account. Then create a new CAPTCHA.


What changes when you move to TrustCaptcha

Section titled “What changes when you move to TrustCaptcha”

hCaptcha and TrustCaptcha both follow the same basic idea: your frontend produces a token and your backend verifies it. The migration is mainly about replacing the frontend widget and updating the server-side validation.

In practice, you will:

  • Remove the hCaptcha JavaScript and the hCaptcha widget container from your pages.
  • Add the TrustCaptcha dependency and the <trustcaptcha-component> web component.
  • Replace the token field you send to your backend with the TrustCaptcha token field (tc-verification-token by default).
  • Replace your server-side verification call to hCaptcha with TrustCaptcha result validation.

Follow these steps to migrate from hCaptcha to TrustCaptcha.

Most hCaptcha setups contain these two parts:

  1. A script tag (often something like this):
Typical hCaptcha script to remove (example)
<script src="https://js.hcaptcha.com/1/api.js" async defer></script>
  1. A widget container inside your form (often like this):
Typical hCaptcha container to remove (example)
<div class="h-captcha" data-sitekey="<your_hcaptcha_site_key>"></div>

Remove both from your page. If you also used custom callbacks, “invisible” triggers, or special form submit logic, remove that too. We will replace it with TrustCaptcha’s widget behavior and events.

TrustCaptcha provides a web component called trustcaptcha-component. It must be placed inside a <form> element and needs a TrustCaptcha sitekey.

TrustCaptcha basic widget example
<script src="https://cdn.trustcomponent.com/trustcaptcha/3.0.x/trustcaptcha.umd.min.js"></script>
<form>
<!-- your input fields -->
<trustcaptcha-component
sitekey="<your_trustcaptcha_site_key>"
></trustcaptcha-component>
<!-- further input fields / submit button -->
</form>

When TrustCaptcha completes, it automatically writes a hidden form field named tc-verification-token. You can also listen to the captchaSolved event if you want to send the token using JavaScript.

For detailed frontend integrations, use the guides below.

3. Replace the token you send to your backend

Section titled “3. Replace the token you send to your backend”

With hCaptcha, the token field is often named h-captcha-response (or your frontend submits it under a similar name).

With TrustCaptcha, the field is tc-verification-token by default.

This means: update the backend code that reads the token from the form request body and switch it to the TrustCaptcha field name. If you submit via JavaScript, you can also read it from the event:

Reading the TrustCaptcha token via event (example)
<script>
const trustcaptchaComponent = document.getElementsByTagName('trustcaptcha-component')[0];
trustcaptchaComponent.addEventListener('captchaSolved', (event) => {
const verificationToken = event.detail;
// Send verificationToken to your backend (e.g., JSON body).
});
</script>

With hCaptcha, you typically call the hCaptcha verification endpoint (often called siteverify) and check whether it succeeded.

With TrustCaptcha, your server exchanges the verification token from the form field tc-verification-token for the verification result, using the TrustComponent SDK and an API key of your project (created in the dashboard under API / Integration). Install the SDK as shown in the result validation overview, then fetch the result and decide based on isVerificationPassed and score (0 = probably human, 1 = probably automated):

Fetch and evaluate the verification result
Terminal window
# The verification id is inside the token (see the result validation overview).
curl "https://api.trustcomponent.com/captcha/v3/verifications/{verificationId}/results" \
-H "Authorization: Bearer <your_api_key>"
Fetch and evaluate the verification result
import { TrustComponent } from '@trustcomponent/sdk';
const tc = new TrustComponent('<your_api_key>');
const result = await tc.captcha.getVerificationResult(request.body['tc-verification-token']);
if (!result.isVerificationPassed || result.score > 0.5) {
// failed or likely automated: reject
}
Fetch and evaluate the verification result
use TrustComponent\TrustComponent;
$tc = new TrustComponent('<your_api_key>');
$result = $tc->captcha()->getVerificationResult($_POST['tc-verification-token']);
if (!$result->isVerificationPassed() || $result->getScore() > 0.5) {
// failed or likely automated: reject
}
Fetch and evaluate the verification result
from trustcomponent import TrustComponent
tc = TrustComponent("<your_api_key>")
result = tc.captcha.get_verification_result(request.form["tc-verification-token"])
if not result.is_verification_passed or result.score > 0.5:
... # failed or likely automated: reject
Fetch and evaluate the verification result
import com.trustcomponent.sdk.TrustComponent;
import com.trustcomponent.sdk.model.CaptchaVerificationResult;
TrustComponent tc = new TrustComponent("<your_api_key>");
CaptchaVerificationResult result = tc.captcha().getVerificationResult(request.getParameter("tc-verification-token"));
if (!result.isVerificationPassed() || result.getScore() > 0.5) {
// failed or likely automated: reject
}
Fetch and evaluate the verification result
using TrustComponent;
using var tc = new TrustComponentClient("<your_api_key>");
var result = await tc.Captcha.GetVerificationResultAsync(Request.Form["tc-verification-token"]);
if (!result.IsVerificationPassed || result.Score > 0.5)
{
// failed or likely automated: reject
}
Fetch and evaluate the verification result
import trustcomponent "github.com/trustcomponent/trustcomponent-go"
tc := trustcomponent.New("<your_api_key>")
result, err := tc.Captcha.GetVerificationResult(ctx, r.FormValue("tc-verification-token"))
if err != nil || !result.IsVerificationPassed || result.Score > 0.5 {
// failed or likely automated: reject
}
Fetch and evaluate the verification result
require 'trustcomponent'
tc = TrustComponent::Client.new('<your_api_key>')
result = tc.captcha.get_verification_result(params['tc-verification-token'])
if !result.is_verification_passed || result.score > 0.5
# failed or likely automated: reject
end
Fetch and evaluate the verification result
let tc = trustcomponent::TrustComponent::new("<your_api_key>");
let result = tc.captcha.get_verification_result(&form.verification_token).await?;
if !result.is_verification_passed || result.score > 0.5 {
// failed or likely automated: reject
}

That is the whole integration. The rest of this page explains the token, the result, how to judge it, the errors and the options.

The result validation overview explains the result, the errors and how to adapt the threshold, in every language of the SDK.


Once you have successfully installed and configured TrustCaptcha on your website, you can use TrustCaptcha to its full extent. However, we still recommend the following additional technical and organizational measures:

  • Security rules: You can find many security settings for your CAPTCHA in the CAPTCHA settings. These include, for example, authorized websites, CAPTCHA bypass for specific IP addresses, bypass keys, IP based blocking, geoblocking, individual difficulty and duration of the CAPTCHA, and much more. Learn more about the security rules.

  • Privacy & GDPR compliance: Include a passage in your privacy policy that refers to the use of TrustCaptcha. We also recommend that you enter into a data processing agreement with us to stay GDPR-compliant. Learn more about data protection.

  • Accessibility & UX: Customize TrustCaptcha to your website so that your website is as accessible as possible and offers the best possible user experience. More about accessibility.

  • Testing: If you use automated testing, make sure that the CAPTCHA does not block it. Learn more about testing.