Each mews/captcha call and its Go equivalent, followed by every place where the Go port behaves differently.
| PHP | Go |
|---|---|
'captcha' => 'required|captcha' | rule.Field(&f.Captcha, rule.Required, captcha.Rule(r)) |
'captcha' => 'required|captcha_api:'.$key.',math' | rule.Field(&f.Captcha, rule.Required, captcha.KeyedWith(key).Profile("math")), or captcha.Keyed() to read the key from the captcha_key field |
captcha_src('flat') | captcha.Src(ctx, "flat"), or {{captchaSrc "flat"}} in a template |
captcha_img('flat', ['class' => 'x']) | captcha.Img(ctx, "flat", captcha.Attr{Name: "class", Value: "x"}), or {{captchaImg "flat" "class" "x"}} |
captcha('flat') | captcha.Image(r, "flat") |
captcha_check($value) | captcha.Check(r, value) |
captcha_api_check($value, $key, 'math') | captcha.CheckKey(ctx, key, value, "math") |
Captcha::create('default', true) | captcha.Issue(ctx, "default"): Key, Sensitive, DataURI() |
config/captcha.php | captcha.New(func(cfg *captcha.Config) { … }), or captcha.ParsePHPConfig |
CAPTCHA_DISABLE | CAPTCHA_DISABLE |
What behaves differently
These differences are deliberate. Each one is tested against the PHP behaviour.
Security
- The API key is an opaque id. With
encryptoff, PHP's key was a bcrypt hash of the answer, so a client could check guesses offline. Nothing the client receives here can check a guess. - A challenge answers only its own profile. PHP's session check accepted an image from any profile.
Here a rule without a profile means
default, so name the profile in the rule when the form shows another one. - The answer is never stored. The store keeps a challenge record with a keyed verifier; a successful check marks the record used, and it's removed when its retention ends.
- The session holds only a marker. The challenge lives in the store, so an old cookie can't revive an earlier challenge. Requesting a keyed challenge never replaces a session one.
- Wrong answers and image requests are limited per client (see Configuration).
captcha_imgescapes attribute values and accepts only safe attribute names. PHP inserted them unescaped. PHP's helper also returned a string, so Blade's{{ }}escaped the whole tag; the Go helper returns markup a template doesn't escape again.
Behaviour
- Missing answers fail. PHP's rule passed a missing or empty captcha when
requiredwas left out. "0"is a valid answer. PHP's rule failed it.- Surrounding spaces are ignored. Answers are trimmed before the comparison.
- An unknown profile is a 404. PHP served the class defaults for any name.
- Settings never leak between profiles. In PHP, a profile could inherit keys the previous profile set.
- Invalid settings stop the application at startup, instead of failing on each request.
HEADissues nothing, and images are sent withCache-Control: no-store.- The JPEG
qualitysetting is used. PHP always encoded at 75. - Math profiles allow at most 3 attempts. A sum has few possible answers.
- The default message is "The :attribute is incorrect." PHP showed the raw key
validation.captcha. - Expiry: a challenge without a deadline (
captcha.NoDeadline) is still removed afterNoDeadlineLifetime(24 hours by default). PHP's cache entry lived forexpireseconds.
Not ported
- The image driver setting. Images are drawn by the package's own Go pipeline;
ParsePHPConfigignoresdriver. - Publishing a config file. Laravel for Go has no config files: settings are set in code, and
ParsePHPConfigreads an exported PHP config. - Lumen routes and output buffering. They don't apply to Laravel for Go.
To move a config file, export it with json_encode(config('captcha')) and read it with
captcha.ParsePHPConfig.