# Migrating from PHP (laravel-rust-captcha)

> In PHP the captcha rule accepted the latest challenge of any profile. Here a rule checks one profile, default unless you name another. If your form shows…

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

## Lookup

| PHP (mews/captcha) | Rust |
| --- | --- |
| `Mews\Captcha\CaptchaServiceProvider` | `CaptchaServiceProvider::new()` in `with_providers` (no auto-discovery) |
| `config/captcha.php` | `CaptchaConfig` in `with_config`, or `CaptchaConfig::from_php_json` |
| `CAPTCHA_DISABLE` | `CAPTCHA_DISABLE` |
| `GET captcha/{config?}` | `GET captcha/{profile?}` |
| `GET captcha/api/{config?}` | `GET captcha/api/{profile?}` |
| `captcha($config)`, `Captcha::create($config)` | the image route, or `CaptchaManager::image` |
| `Captcha::create($config, true)` | `laravel_rust_captcha::issue(&request, profile)` |
| `captcha_src($config)`, `Captcha::src` | `src(profile)`; MiniJinja `captcha_src(profile)` |
| `captcha_img($config, $attrs)`, `Captcha::img` | `img(profile, attrs)`; MiniJinja `captcha_img(profile, **attrs)` |
| `captcha_check($value)`, `Captcha::check` | `check(&request, profile, value)` → `Verdict` |
| `captcha_api_check($value, $key, $config)`, `Captcha::check_api` | `check_keyed(ip, key, profile, value)` → `Verdict` |
| `'captcha'` rule | `Captcha::session()` |
| `'captcha_api:'.$key.','.$config` | `Captcha::keyed().profile(config)`, key in the `captcha_key` field |
| a prebound `ImageManager` | `CaptchaServiceProvider::new().renderer(MyRenderer)` |
| `captcha.driver` (`gd`, `imagick`) | none: one built-in renderer |
| Lumen routes | none |
| `ob_clean()` before the image | not needed: responses aren't written through an output buffer |

## Name the profile in the rule

In PHP the `captcha` rule accepted the latest challenge of any profile. Here a rule checks one profile,
`default` unless you name another. If your form shows `captcha_src('contact')`, the rule becomes
`Captcha::session().profile("contact")`. With `APP_DEBUG` on, a check that finds a challenge for another
profile logs a warning naming both.

## Intended differences

Every difference has a reason. The numbers match the plan and `conformance/fixtures/differences.json`,
which the tests check.

| # | PHP | Here | Why |
| --- | --- | --- | --- |
| 1 | The API `key` is the bcrypt hash of the answer | An opaque random id | A client could check guesses offline |
| 2 | bcrypt per image; `encrypt` option | HMAC-SHA256; `encrypt` ignored | CPU per image; nothing secret leaves the server |
| 3 | One challenge per session, stored in the session; the API route overwrites it | One current challenge per session and profile, kept by the store; the API route has no session | Tabs, APIs, Inertia; old cookies can't revive challenges |
| 4 | Characters picked with `rand()` | The OS random generator, without bias | Security |
| 5 | Checking reads, then deletes | At most one pass, every comparison counted | Simultaneous submissions both passed |
| 6 | Any profile's challenge passes any form | Bound to the rule's profile | A weak profile can't pass a strict form |
| 7 | `captcha_img` doesn't escape | Escaped, safe names only, default `alt` | Cross-site scripting |
| 8 | `quality` ignored (always 75) | Honoured | It's a documented key |
| 9 | An unknown profile serves the class defaults | 404 | Typos show; no probing |
| 10 | `Cache-Control: no-cache, private` | `no-store` | Images must never be cached |
| 11 | A string alphabet is split by bytes | By characters | Multibyte alphabets |
| 12 | Surrounding spaces fail | Trimmed | Laravel's `TrimStrings` did this anyway |
| 13 | Layout divides by `length`, so math text overflowed | By the drawn text length | Math profiles with a short length |
| 14 | The rule passes a blank field without `required` | Fails | Fail closed |
| 15 | The rule fails the answer `"0"` | Passes | PHP's falsy-string check |
| 16 | Message `validation.captcha` | "The :attribute is incorrect." | No raw key on screen |
| 17 | A common fork ignores `expire` | `expire: None` keeps the challenge up to `retention` | Bounded store |
| 18 | Lumen; GD or Imagick | One built-in renderer | Single binary |
| 19 | `blur` up to 100; no limits | The limits in [Configuration](https://oss.bowerbird.si/captcha/docs/configuration/) | Bounded work per image |
| 20 | The facade keeps settings between profiles | Each profile is resolved fresh | Settings leaked into the next profile |
| 21 | Any cache store | Shared, non-failover stores; SQLite needs its own file | One pass needs one authority |
| 22 | `HEAD` on the image route issues a challenge | `HEAD` issues nothing | A probe shouldn't replace the visitor's image |
| 23 | `length` 0 fails every request | Out-of-range settings stop the app at boot | Mistakes show at deploy time |

## Tests

PHP tests that wrote `captcha` into the session and `captcha_<md5>` into the cache move to
`testing::seed` or `testing::fix_answers`; see [Testing](https://oss.bowerbird.si/captcha/docs/testing/).
