# Getting started (laravel-rust-captcha)

> Install the crate, register its provider and protect your first form with an image captcha.

- 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/docs/getting-started/
- Source: https://github.com/bowerbird-si/laravel-rust-captcha/blob/57c677c77d6c928790e0acaf24e0b3f0ff06f29c/docs/getting-started.md

Install the crate, register its provider and protect your first form with an image captcha.

## Install

Add the crate:

```shellscript
cargo add laravel-rust-captcha
```

Register the provider and configure the input exemptions in `src/app.rs`:

```rust
use laravel_rust_captcha::CaptchaServiceProvider;

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

That's all for a first form. The provider registers two routes, `GET /captcha/{profile?}` for the
image and `GET /captcha/api/{profile?}` for keyed challenges, the MiniJinja functions and the
`Captcha` validation rule.

## Protect a form

Show the image and an input in the form's view:

```html
<img src="{{ captcha_src() }}" alt="captcha">
<input type="text" name="captcha" autocomplete="off">
{% if error('captcha') %}<p>{{ error('captcha') }}</p>{% endif %}
```

Validate the answer in the form's input struct:

```rust
use laravel_rust_captcha::Captcha;

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

The rule checks the image the visitor last loaded. A correct answer passes once. By default a
challenge allows one attempt within 60 seconds, as mews/captcha does: after a wrong answer, the visitor
needs a new image. See [Configuration](https://oss.bowerbird.si/captcha/docs/configuration/) to change that.

## Before production

Challenges live in a cache store that every process of your app shares. The default `memory` store
works in development but is refused in production unless the app runs as one process. Read
[Deployment](https://oss.bowerbird.si/captcha/docs/deployment/).
