Skip to content

Migrate to AceCaptcha

From Turnstile, reCAPTCHA or hCaptcha, the switch is a few lines: swap the script and the widget, change the verify URL and secret, and branch on decision.

Your integration keeps its shape: the page gets a token, the form carries it to your backend, and your backend redeems it. Three things change:

  • The check is invisible until it’s needed. It runs when the visitor uses the form, and most visitors never see it.
  • The verify URL and secret become https://hc.acecaptcha.com/v1/siteverify and your ace_secret_….
  • Your backend branches on decision.

Important

Don’t stop at success

A handler that checks only success lets blocked bots through: success: true only means the token is genuine, unexpired and unused. Every “after” sample below reads decision.

The samples use Node with Express-style req and res. For PHP, Python and Go, and for timeouts, retries and outage handling, see the siteverify samples.

From Turnstile

Page

Turnstile · login.html
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script><form action="/login" method="post">  <input name="email" type="email" required>  <div class="cf-turnstile" data-sitekey="YOUR_TURNSTILE_SITEKEY"></div>  <button>Sign in</button></form>
AceCaptcha · login.html
<script src="https://hc.acecaptcha.com/v1/client.js" defer></script><form action="/login" method="post">  <input name="email" type="email" required>  <div class="ace-captcha" data-sitekey="ace_site_xxxxxxxxxxxxxxxxxxxxxx" data-action="login"></div>  <button>Sign in</button></form>

Server

Turnstile · login route
const reply = await fetch('https://challenges.cloudflare.com/turnstile/v0/siteverify', {  method: 'POST',  headers: { 'content-type': 'application/json' },  body: JSON.stringify({    secret: process.env.TURNSTILE_SECRET,    response: req.body['cf-turnstile-response'],    remoteip: req.ip,  }),})const result = await reply.json()if (!result.success) {  return res.status(403).send('Please try again.')}
AceCaptcha · login route
const reply = await fetch('https://hc.acecaptcha.com/v1/siteverify', {  method: 'POST',  headers: { 'content-type': 'application/json' },  body: JSON.stringify({    secret: process.env.ACE_SECRET,    response: req.body['ace-token'],    remoteip: req.ip,    action: 'login',  }),})const result = await reply.json()if (!result.success) {  return res.status(403).send('Please try again.')}// success only means the token is genuine. Act on decision.const decision = result.mode === 'shadow' ? 'allow' : result.decisionif (decision === 'block') {  return res.status(403).send('Please try again.')}if (decision === 'allow_limited') {  // proceed, with tighter limits on this request}

On the page, data-action, data-theme, data-callback and data-error-callback work like Turnstile’s. Siteverify takes the same request fields and answers with the same reply fields and error codes, so the rest of your handler stays. See Turnstile compatibility.

From reCAPTCHA

Page

reCAPTCHA v3 · login.html
<script src="https://www.google.com/recaptcha/api.js?render=YOUR_RECAPTCHA_SITEKEY"></script><form action="/login" method="post">  <input name="email" type="email" required>  <input name="g-recaptcha-response" type="hidden">  <button>Sign in</button></form><script>  const form = document.querySelector('form')  form.addEventListener('submit', (event) => {    event.preventDefault()    grecaptcha.ready(async () => {      form.elements['g-recaptcha-response'].value =        await grecaptcha.execute('YOUR_RECAPTCHA_SITEKEY', { action: 'login' })      form.submit()    })  })</script>
AceCaptcha · login.html
<script src="https://hc.acecaptcha.com/v1/client.js" defer></script><form action="/login" method="post">  <input name="email" type="email" required>  <div class="ace-captcha" data-sitekey="ace_site_xxxxxxxxxxxxxxxxxxxxxx" data-action="login"></div>  <button>Sign in</button></form>

The submit handler goes: the check holds the submit by itself. To keep calling for tokens from your own code, see getting tokens yourself. Coming from the v2 checkbox, the page changes like the hCaptcha one below.

Server

reCAPTCHA · login route
const reply = await fetch('https://www.google.com/recaptcha/api/siteverify', {  method: 'POST',  body: new URLSearchParams({    secret: process.env.RECAPTCHA_SECRET,    response: req.body['g-recaptcha-response'],  }),})const result = await reply.json()if (!result.success || result.action !== 'login' || result.score < 0.5) {  return res.status(403).send('Please try again.')}
AceCaptcha · login route
const reply = await fetch('https://hc.acecaptcha.com/v1/siteverify', {  method: 'POST',  body: new URLSearchParams({    secret: process.env.ACE_SECRET,    response: req.body['ace-token'],    action: 'login',  }),})const result = await reply.json()if (!result.success) {  return res.status(403).send('Please try again.')}// success only means the token is genuine. Act on decision.const decision = result.mode === 'shadow' ? 'allow' : result.decisionif (decision === 'block') {  return res.status(403).send('Please try again.')}if (decision === 'allow_limited') {  // proceed, with tighter limits on this request}

Siteverify accepts the same form-encoded body. Instead of a score to compare, the reply carries a decision. The action check moves to AceCaptcha: send action, and a token issued for another action fails with action-mismatch.

From hCaptcha

Page

hCaptcha · login.html
<script src="https://js.hcaptcha.com/1/api.js" async defer></script><form action="/login" method="post">  <input name="email" type="email" required>  <div class="h-captcha" data-sitekey="YOUR_HCAPTCHA_SITEKEY"></div>  <button>Sign in</button></form>
AceCaptcha · login.html
<script src="https://hc.acecaptcha.com/v1/client.js" defer></script><form action="/login" method="post">  <input name="email" type="email" required>  <div class="ace-captcha" data-sitekey="ace_site_xxxxxxxxxxxxxxxxxxxxxx" data-action="login"></div>  <button>Sign in</button></form>

Server

hCaptcha · login route
const reply = await fetch('https://api.hcaptcha.com/siteverify', {  method: 'POST',  body: new URLSearchParams({    secret: process.env.HCAPTCHA_SECRET,    response: req.body['h-captcha-response'],    remoteip: req.ip,  }),})const result = await reply.json()if (!result.success) {  return res.status(403).send('Please try again.')}
AceCaptcha · login route
const reply = await fetch('https://hc.acecaptcha.com/v1/siteverify', {  method: 'POST',  body: new URLSearchParams({    secret: process.env.ACE_SECRET,    response: req.body['ace-token'],    remoteip: req.ip,    action: 'login',  }),})const result = await reply.json()if (!result.success) {  return res.status(403).send('Please try again.')}// success only means the token is genuine. Act on decision.const decision = result.mode === 'shadow' ? 'allow' : result.decisionif (decision === 'block') {  return res.status(403).send('Please try again.')}if (decision === 'allow_limited') {  // proceed, with tighter limits on this request}

Roll out safely

New sites start in shadow mode. Ship the switch, log the decisions your backend gets, and watch them in the dashboard’s usage stats. When the decisions look right for your traffic, switch the site to enforce.

Checklist

  • The script tag points at https://hc.acecaptcha.com/v1/client.js, and the old one is gone.
  • The old widget is replaced by <div class="ace-captcha"> inside the form, with your sitekey and an action.
  • Your backend reads the token from ace-token.
  • Your backend calls the AceCaptcha siteverify URL with ACE_SECRET, from the server only.
  • Your handler acts on decision, not just success.
  • Your Content Security Policy allows hc.acecaptcha.com.
  • Every hostname that serves the form is listed on the site, over https.