# laravel-go-captcha

> Go port of mews/captcha: A self-hosted image captcha for Laravel for Go, ported from mews/captcha

- Package: laravel-go-captcha (Laravel for Go, alpha), go modules: `github.com/bowerbird-si/laravel-go-captcha`
- Maintenance: active; Latest release: 0.1.0 (2026-12-04); Framework: go.laravel.com v0.2.0 or later; Go: Go 1.27 or later; Licence: MIT
- Links: [Repository](https://github.com/bowerbird-si/laravel-go-captcha), [pkg.go.dev](https://pkg.go.dev/github.com/bowerbird-si/laravel-go-captcha@v0.1.0), [Changelog](https://oss.bowerbird.si/go-captcha/docs/changelog/), [Contributing](https://github.com/bowerbird-si/laravel-go-captcha/blob/7a10d1c56d2e1a3e3e6618d025657dda5d5385cf/CONTRIBUTING.md), [Security policy](https://github.com/bowerbird-si/laravel-go-captcha/blob/7a10d1c56d2e1a3e3e6618d025657dda5d5385cf/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 bundled fonts ship with their own licences.
- PHP parity: core (52 covered, 35 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/go-captcha/
- Documentation: https://oss.bowerbird.si/go-captcha/docs.md

Draws the captcha on your own server and checks the answer there, so nothing goes to a third party. It keeps mews/captcha's profiles, routes and rules, and is tested against fixtures the PHP package generates. Each challenge passes at most once.

```shell
go get github.com/bowerbird-si/laravel-go-captcha
```

- **Session and keyed captchas.** A session captcha for server-rendered forms, and a keyed one for APIs and single-page apps that never touches the session.
- **mews/captcha's profiles and drawing.** The five shipped profiles, custom ones and math captchas, drawn with the bundled fonts and backgrounds; GD's filters and resize are matched.
- **One pass per challenge.** A check consumes the challenge atomically on Redis or the database cache: of many simultaneous correct answers, exactly one passes.
- **Nothing secret leaves the server.** The answer is never stored or sent. The store keeps a keyed verifier, and the API key is an opaque random id.
- **Limits built in.** Wrong answers are limited per client and profile, and image requests per client, on the same store as the challenges.
- **Moving from PHP.** `ParsePHPConfig` reads an exported `config('captcha')`, and the guide maps every mews/captcha call to its Go equivalent.

### A session form

Register the package, show the image, and check the answer with the rule.

```go
// bootstrap/app.go
Packages: []laravel.Package{captcha.New()},

// The form: <img src="{{captchaSrc "default"}}"> and <input name="captcha">
func (f *ContactForm) Rules(r *web.Request) (validation.Rules, error) {
	return validation.For(f, rule.Field(&f.Captcha, rule.Required, captcha.Rule(r))), nil
}
```

### A keyed captcha for an API

The client fetches `GET /captcha/api/default`, shows `img`, and sends the answer back with `key`.

```go
type KeyedForm struct {
	Captcha    string `json:"captcha"`
	CaptchaKey string `json:"captcha_key"`
}

func (f *KeyedForm) Rules() validation.Rules {
	return validation.For(f, rule.Field(&f.Captcha, rule.Required, captcha.Keyed()))
}
```
