ancaptcha (0.4.2)

Published 2026-11-08 07:40:52 +00:00 by maverick in maverick/ancaptcha

Installation

[registries.forgejo]
index = "sparse+" # Sparse index
# index = "" # Git

[net]
git-fetch-with-cli = true
cargo add ancaptcha@0.4.2 --registry forgejo

About this package

Stateless human verification engine using interactive CSS instead of JavaScript.

anCaptcha

A No-JS, stateless captcha engine implemented in Rust. Originally designed for the darknet and Tor hidden services, to provide human verification without requiring JavaScript.

Core Engine

This crate provides the core logic for:

  • Stateless Tokens: Authenticated encryption (ChaCha20-Poly1305) stores challenge state without server sessions.
  • Resource Processing: JIT asset warming and noise injection to thwart automated solvers.
  • Multi-Modal Challenges: Supports Rotate, Slider, and Find-the-Pair verification styles.

Usage

1. Initialize Asset Cache

It is recommended to initialize and warm up the cache during startup. Since warming up involves heavy image processing, use a blocking task if in an async environment. You can warm up only the styles you intend to use.

use ancaptcha::{init_cache, CaptchaStyle};

let cache = init_cache();
// Recommended: Warm up only the styles you need in a background thread
std::thread::spawn(move || {
    cache.warm_up(CaptchaStyle::Rotate);
    // cache.warm_up(CaptchaStyle::Slider);
    // cache.warm_up(CaptchaStyle::Pair);
});

2. Generate a Challenge

Initialize the engine with a 32-byte secret key (e.g., from an environment variable).

use ancaptcha::{AnCaptcha, Config, Difficulty};

let secret = [0u8; 32]; // Replace with real secret
let ac = AnCaptcha::new(Config::new(secret).with_difficulty(Difficulty::Medium));

// Choose your style: generate_rotate, generate_slider, or generate_pair
let bundle = ac.generate_slider(None).expect("Failed to generate");

// bundle.html contains the combined HTML and CSS <style> block
// bundle.token must be included in your form submission

3. Verify Submission

You can verify the raw form-data directly (automatic) or verify individual values.

// Automatic verification from a HashMap<String, Vec<String>>
let is_valid = ac.verify_request(&form_map).unwrap_or(false);

(c) 2026 Maverick. Apache-2.0.

Dependencies

ID Version
base64 ^0.23.1
bincode-next ^3.1.1
chacha20poly1305 ^0.11.0
html-escape ^0.3.1
image ^0.25.10
rand ^0.10.3
rayon ^1.12.0
serde ^1.0.229
subtle ^2.6.1
thiserror ^2.0.21
proptest ^1.12.0
image ^0.25.10

Keywords

captcha no-js privacy ffi
Details
Cargo
2026-11-08 07:40:52 +00:00
9
Maverick
Apache-2.0
313 KiB
Assets (1)
Versions (8) View all
0.4.2 2026-11-08
0.4.1 2026-08-23
0.4.0 2026-06-06
0.3.0 2026-04-19
0.2.0 2026-04-17