# laravel-rust-captcha

> Rust port of mews/captcha: mews/captcha's image captcha, in Laravel for Rust.

- Package: laravel-rust-captcha (Laravel for Rust, alpha), crates: `laravel-rust-captcha`
- Maintenance: active; Latest release: 0.1.0 (2026-12-04); Framework: laravel-rust 0.2.x; MSRV: Rust 1.99 or later; Licence: MIT
- Links: [Repository](https://github.com/bowerbird-si/laravel-rust-captcha), [crates.io](https://crates.io/crates/laravel-rust-captcha/0.1.0), [docs.rs](https://docs.rs/laravel-rust-captcha/0.1.0), [Changelog](https://oss.bowerbird.si/captcha/docs/changelog/), [Contributing](https://github.com/bowerbird-si/laravel-rust-captcha/blob/57c677c77d6c928790e0acaf24e0b3f0ff06f29c/CONTRIBUTING.md), [Security policy](https://github.com/bowerbird-si/laravel-rust-captcha/blob/57c677c77d6c928790e0acaf24e0b3f0ff06f29c/SECURITY.md)
- Based on: [mews/captcha](https://github.com/mewebstudio/captcha): The captcha package this ports: profiles, config keys, routes and validation, following version 3.5.1. Its backgrounds and fonts ship with their own licences.
- PHP parity: full (54 covered, 33 diverged, 0 planned of 87 abilities; 44 fixtures; follows mews/captcha 3.5.1; verified 2026-12-04)
- Community package, not affiliated with Laravel.
- HTML version: https://oss.bowerbird.si/captcha/
- Documentation: https://oss.bowerbird.si/captcha/docs.md

A self-hosted image captcha with mews/captcha's profiles, routes, helpers and validation rules. Nothing is sent to Google or Cloudflare, and each challenge passes at most once, even when two submissions arrive together.

```shell
cargo add laravel-rust-captcha
```

- **PHP is the oracle.** The real mews/captcha 3.5.1 runs 44 scenarios in a pinned PHP image. Every ability in `parity.toml` is covered by a test or listed as a deliberate difference with its reason.
- **One pass per challenge.** Answers are verified with a keyed HMAC and never stored or sent. A correct answer passes only for the check that removes the challenge, tested on memory, SQLite, PostgreSQL and Redis.
- **Session and keyed modes.** `Captcha::session()` checks the image the visitor last loaded, as in PHP. `Captcha::keyed()` takes the challenge id from a form field, for Inertia, APIs and pages with several captchas.
- **Images like PHP's.** Profiles with every PHP setting, the PHP package's fonts and backgrounds, math captchas, and filters that match GD within one colour unit.

### A protected form

Register the provider, show the image, and validate the answer with the `Captcha` rule.

```rust
use laravel_rust_captcha::{Captcha, CaptchaServiceProvider};

Application::configure()
    .with_providers(|providers| {
        providers.add(CaptchaServiceProvider::new());
    })
    .with_middleware(|middleware, config| {
        CaptchaServiceProvider::configure_input(middleware, config, &[]);
    });

#[laravel::input]
#[validate(anyone)]
pub struct StoreTopic {
    #[validate(required, Captcha::session())]
    captcha: String,
}
```

### In a MiniJinja view

The image URL changes on every render, so a refreshed form gets a new challenge.

```jinja
<img src="{{ captcha_src() }}" alt="captcha">
<input type="text" name="captcha" autocomplete="off">
```
