ALTCHA uses a proof-of-work mechanism to protect your website, APIs, and online services from spam and abuse. Unlike other solutions, ALTCHA is self-hosted, does not use cookies nor fingerprinting, does not track users, and is fully compliant with GDPR.
Visit ALTCHA for more information.
ALTCHA widget is distributed as a "Web Component" and supports all modern browsers.
npm install altcha
import altcha
in your main file:
import 'altcha';
or insert <script>
tag to your website:
<script async defer src="/altcha.js" type="module"></script>
CDN: https://cdn.jsdelivr.net/gh/altcha-org/altcha@main/dist/altcha.min.js
<altcha-widget>
tag in your forms<form>
<altcha-widget
challengeurl="https://..."
></altcha-widget>
</form>
See the configuration below or visit the website integration documentation.
See server documentation for more details.
ALTCHA's default bundle is lightweight, combining all assets, including CSS and the JavaScript Web Worker, into a single file. When GZIPped, it totals only 17 kB, making ALTCHA’s widget 94% smaller than reCAPTCHA.
Distribution | Size (GZIPped) |
---|---|
ALTCHA (v1.x) | 17 kB |
hCaptcha | 48+ kB |
reCAPTCHA | 270+ kB |
The default distribution bundle of the WebComponent includes styles and the worker in a single file. This might cause issues with strict CSP rules. If you require strict CSP compliance, consider using the scripts located in the /dist_external
directory. For more details, please refer to the documentation.
Required options (at least one is required):
challengeurl
, provide the data here.Additional options:
off
, onfocus
, onload
, onsubmit
).auto
, top
, bottom
).button[type="submit"]
in the related form).12
).navigator.hardwareConcurrency || 8
, max value 16
)../worker.js
, only works with external
build).Spam Filter-related options:
spamfilter
option. If enabled, it will block form submission and fail verification if the Spam Filter returns a negative classification. This prevents form submission.spamfilter
option is used. Override this setting only if using a custom server implementation.Data Obfuscation options:
altcha/obfuscation
plugin). Use only without challengeurl
/challengejson
.Development / Testing options:
challengeurl
.Version 0.9.x introduced plugins that can be enabled by importing individual plugin scripts:
import 'altcha/obfuscation';
import 'altcha';
It is recommended to import plugins before the main altcha
package to ensure proper registration before any widget instance is created.
Available plugins built-in to the altcha
package:
altcha/analytics
: Enable analytics with ALTCHA Forms. See HTML submissions documentation.altcha/obfuscation
: Enable obfuscation for sensitive data such as email addresses or phone numbers.altcha/upload
: Enable file upload from type=file
fields to ALTCHA Forms. See HTML submissions documentation.To enable specific plugins for a particular instance of the widget, use the plugins
attribute in the widget tag. List the names of the plugins you want to enable, separated by commas, such as plugins="analytics,obfuscation"
. Plugins still need to be imported as described above. The plugins
attribute only specifies which plugins should be active for that instance, even if other plugins are already imported.
To configure the widget programmatically, use the configure()
method:
document.querySelector('#altcha').configure({
challenge: {
algorithm: 'SHA-256',
challenge: '...',
salt: '...',
signature: '...',
},
strings: {
label: 'Verify',
},
});
Available configuration options:
export interface Configure {
auto?: 'off' | 'onfocus' | 'onload' | 'onsubmit';
challenge?: {
algorithm: string;
challenge: string;
maxnumber?: number;
salt: string;
signature: string;
};
challengeurl?: string;
debug?: boolean;
delay?: number;
expire?: number;
floating?: 'auto' | 'top' | 'bottom';
floatinganchor?: string;
floatingoffset?: number;
autorenew?: boolean;
hidefooter?: boolean;
hidelogo?: boolean;
maxnumber?: number;
mockerror?: boolean;
name?: string;
obfuscated?: string;
refetchonexpire?: boolean;
spamfilter?: boolean | 'ipAddress' | SpamFilter;
strings?: {
error: string;
expired: string;
footer: string;
label: string;
verified: string;
verifying: string;
waitAlert: string;
}
test?: boolean | number | 'delay';
verifyurl?: string;
workers?: number;
workerurl?: string;
}
spamfilter
).state
changes.enum State {
ERROR = 'error',
VERIFIED = 'verified',
VERIFYING = 'verifying',
UNVERIFIED = 'unverified',
EXPIRED = 'expired',
};
Using events:
document.querySelector('#altcha').addEventListener('statechange', (ev) => {
// See enum State above
console.log('state:', ev.detail.state);
});
[!IMPORTANT]
Both programmatic configuration and event listeners have to called/attached after the ALTCHA script loads, such as withinwindow.addEventListener('load', ...)
.
The widget integrates with ALTCHA's Anti-Spam solution to allow checking submitted form data for potential spam.
The Spam Filter API analyzes various signals in the submitted data to determine if it exhibits characteristics of spam. This non-invasive filtering helps reduce spam submissions without frustrating legitimate users.
The Spam Filter can be enabled with default configuration by setting the spamfilter
option to true
, or ipAddress
to verify only the IP address and the time zone, or it can be customized using the following configuration schema:
interface SpamFilter {
blockedCountries?: string[];
classifier?: string;
disableRules?: string[];
email?: string | false;
expectedCountries?: string[];
expectedLanguages?: string[];
fields?: string[] | false;
ipAddress?: string | false;
text?: string | string[];
timeZone?: string | false;
}
SpamFilter configuration options:
false
.false
.false
.To include the email field into fields
(for easier server-side verification), configure the list of input names using the spamfilter.fields: string[]
option.
By default, all text inputs and textareas within the parent form are spam-checked. To exclude a specific input, add the data-no-spamfilter
attribute. Alternatively, explicitly list the checked fields using the fields
config option.
See Contributing Guide and please follow our Code of Conduct.
MIT