How I Stopped Fake Sign-Ups with Invisible reCAPTCHA v3
Published March 24, 2026, 2:52 a.m. by wielandtech
I was getting a slow trickle of fake accounts and spam through the sign-up and contact forms. Never a lot, but enough that I stopped trusting my own user count.
So I added Google's invisible reCAPTCHA v3. Unlike the old checkbox, there's no "I'm not a robot" step. Every request gets a score for how human it looks, and you pick the cutoff. Real users don't see anything.
Load the script:
<script src="https://www.google.com/recaptcha/api.js?render=YOUR_SITE_KEY"></script>
Grab a token when the form is submitted:
async function getRecaptchaToken(action) {
return await grecaptcha.execute("YOUR_SITE_KEY", { action });
}
document.querySelector("#signup-form").addEventListener("submit", async (e) => {
e.preventDefault();
const token = await getRecaptchaToken("signup");
const formData = new FormData(e.target);
formData.append("recaptcha_token", token);
await fetch("/api/signup", { method: "POST", body: formData });
});
Verify it on the backend:
import httpx
RECAPTCHA_SECRET = "YOUR_SECRET_KEY"
async def verify_recaptcha(token: str) -> float:
async with httpx.AsyncClient() as client:
resp = await client.post(
"https://www.google.com/recaptcha/api/siteverify",
data={"secret": RECAPTCHA_SECRET, "response": token},
)
return resp.json().get("score", 0.0)
Then reject anything under 0.5:
score = await verify_recaptcha(token)
if score < 0.5:
raise ValueError("Suspicious activity detected")
I haven't had a single fake account since. Took about an hour, and I probably should've done it the day I put a form on the internet.
Please log in to add a comment.