Saltearse al contenido

Esta página aún no está disponible en tu idioma.

Angular Captcha Integration

ALTCHA is a next-generation, privacy-first CAPTCHA solution that protects your Angular applications from bots and spam without tracking users or using cookies. This guide walks you through integrating ALTCHA in your Angular projects for secure, GDPR-compliant Angular Captcha implementation.

Example Project

Why Use ALTCHA in Angular?

Using Angular Captcha integration with ALTCHA offers multiple advantages:

  • Privacy-first: No cookies or user tracking.
  • Regulation compliant: Fully GDPR and CCPA compliant.
  • Accessible: Works for all users, including those using assistive technologies.
  • Lightweight: Minimal performance impact on your Angular app.

Integrating ALTCHA ensures your forms and user interactions are protected from automated abuse without compromising user experience.

Installation

Install ALTCHA via npm:

Terminal window
npm install altcha

Or with yarn:

Terminal window
yarn add altcha

Basic Integration in Angular

  1. Import ALTCHA in your Angular component or module:
import 'altcha';
  1. Add the ALTCHA WebComponent to your Angular template:
import { Component } from '@angular/core';
@Component({
selector: 'app-contact-form',
template: `
<form (ngSubmit)="onSubmit(contactForm)" #contactForm="ngForm">
<input type="text" name="name" ngModel placeholder="Your Name" required />
<input type="email" name="email" ngModel placeholder="Your Email" required />
<!-- ALTCHA WebComponent -->
<altcha-widget challengeurl="https://your-challenge-url"></altcha-widget>
<button type="submit">Submit</button>
</form>
`
})
export class ContactFormComponent {
onSubmit(form: any) {
if (form.valid) {
// handle form submission
console.log('Form submitted', form.value);
}
}
}
  1. Verify the CAPTCHA payload on your backend:

Always verify the ALTCHA token server-side to prevent bypasses. Example using Node.js with Hono and altcha-lib:

import { Hono } from 'hono';
import { verifySolution } from 'altcha-lib';
const hmacKey = 'your-secret-key'; // Replace with your HMAC secret
const app = new Hono();
app.post('/submit', async (c) => {
const formData = await c.req.formData();
const altchaToken = formData.get('altcha');
if (!altchaToken) {
return c.json({ error: 'Altcha payload missing' }, 400);
}
const verified = await verifySolution(String(altchaToken), hmacKey);
if (!verified) {
return c.json({ error: 'Invalid Altcha payload' }, 400);
}
// TODO: process form submission
return c.json({ ok: true });
});

For detailed server guides, see Server Integration. Full server source code is available here: Node.js Starter Project.

Getting the Challenge URL

ALTCHA is self-hosted. To get the challenge URL, integrate ALTCHA on your backend or install ALTCHA Sentinel. See Server Integration for step-by-step instructions in multiple languages.

Customizing the Captcha Widget

You can customize the ALTCHA widget for your website’s UX:

Best Practices for Captcha Angular Integration

Frequently Asked Questions

Q: Can I use ALTCHA’s Angular Captcha with TypeScript?
Yes! ALTCHA Angular fully supports TypeScript with proper types.

Q: Does ALTCHA’s Angular Captcha require cookies?
No. ALTCHA is fully cookie-free and does not track users.

Q: Does ALTCHA’s Angular Captcha require external services?
No. ALTCHA is fully self-hosted, no external services, no data is ever shared with anyone.

Q: Is ALTCHA’s Angular Captcha accessible?
Yes. ALTCHA meets WCAG accessibility standards.