# Validation (laravel-rust-captcha)

> easier profile can't pass a stricter form. In PHP any challenge passed any form.

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

## The rule

```rust
use laravel_rust_captcha::Captcha;

#[validate(required, Captcha::session())]                 // PHP: 'required|captcha'
#[validate(required, Captcha::session().profile("contact"))]
#[validate(required, Captcha::keyed().profile("math"))]   // PHP: 'required|captcha_api:'.$key.',math'
#[validate(required, Captcha::keyed().key_field("key"))]
```

- Without `profile`, the profile is `default`. A challenge issued for another profile fails, so an
  easier profile can't pass a stricter form. In PHP any challenge passed any form.
- The rule is implicit: a missing or blank answer fails even without `required`. In PHP the rule
  passed an empty field unless `required` came first.
- Session mode needs the route in the `web` middleware group. Without a session, the request fails
  with an error instead of a wrong-answer message.
- With `CAPTCHA_DISABLE=true`, the rule passes, as in PHP.

## Messages

The default message is "The :attribute is incorrect.". PHP showed the raw key `validation.captcha`.
Give `required` its own message to tell a missing answer from a wrong one:

```rust
#[validate(
    required.message("Please enter the security code."),
    Captcha::session().profile("contact").message("The security code is incorrect."),
    label = "security code"
)]
captcha: String,
```

## Checking by hand

```rust
use laravel_rust_captcha::{Verdict, check, check_keyed};

match check(&request, "contact", &answer).await? {
    Verdict::Passed => {}
    Verdict::Wrong { remaining } => { /* remaining: attempts left, None when unlimited */ }
    Verdict::Expired | Verdict::Missing | Verdict::Exhausted | Verdict::Throttled | _ => {}
}
let verdict = check_keyed(request.ip(), &key, "math", &answer).await?;
```

| Verdict | Meaning |
| --- | --- |
| `Passed` | Correct. This check used the challenge up; no other check can pass it. |
| `Wrong { remaining }` | Wrong. `Some(0)` means the challenge is spent. |
| `Expired` | Past the deadline. |
| `Missing` | No open challenge: never issued, used, replaced by a newer image, or gone after its deadline. |
| `ProfileMismatch` | A keyed challenge of another profile. It is not used up. |
| `Exhausted` | The attempt limit was reached before this check. |
| `Throttled` | Too many wrong answers from this client for this profile in the last minute. |

An error (`Err`) means the store failed or timed out. The check fails closed: it never passes on an
error. PHP's `captcha_check` and `captcha_api_check` returned `true` or `false`; `verdict.passed()`
gives the same.
