# Add a Password Reset Flow to a Symfony App

Yes. An agent adds a request-by-email and reset-by-token flow with symfonycasts/reset-password-bundle, tests it with PHPUnit, and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/add-password-reset/symfony/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads how sign-in and email already work before it adds anything. In an app shaped like symfony/demo, `composer.json` requires `symfony/framework-bundle` ^8 on PHP 8.4, `symfony/security-bundle`, `symfony/mailer`, `symfony/form` and `symfony/validator`, with `symfony/maker-bundle` ^1.36 and `phpunit/phpunit` ^11.5 in `require-dev`. `config/packages/security.yaml` has one `main` firewall with `form_login` on the `security_login` route, `remember_me` and CSRF on login and logout; the `database_users` provider loads `App\Entity\User` by `username`. `src/Controller/SecurityController.php` renders `templates/security/login.html.twig`, which has no forgotten-password link. `src/Controller/UserController.php` already changes a password for a signed-in user through `ChangePasswordType`, so the only missing path is the one for someone who cannot sign in. `User` has a unique `email` column, `UserRepository` exposes `findOneByEmail`, and `src/EventSubscriber/CommentNotificationSubscriber.php` shows the house way to send mail: `MailerInterface`, `%app.notifications.email_sender%` from `config/services.yaml`, subject and body through `TranslatorInterface`.

It requires `symfonycasts/reset-password-bundle` with Composer and runs `bin/console make:reset-password`, then edits what the maker generated to match the project. The maker adds `src/Entity/ResetPasswordRequest.php`, `src/Repository/ResetPasswordRequestRepository.php`, `src/Controller/ResetPasswordController.php` with the `/reset-password`, `/reset-password/check-email` and `/reset-password/reset/{token}` routes, form types for the request and the new password, templates under `templates/reset_password/` and `config/packages/reset_password.yaml`. The agent renames the generated change-password form to `ResetPasswordType` so it does not collide with the existing `ChangePasswordType`, moves the controller's routes under the `/{_locale}` prefix that `config/routes.yaml` applies to every controller, sets the sender from `%app.notifications.email_sender%`, and keeps the hashing rule in `security.yaml` so the new password goes through the same `auto` hasher the login form checks against.

The request page takes an email, and whether or not that email exists it redirects to the check-email page with the same wording, so the form cannot be used to learn which accounts exist. For a known user it stores a hashed selector and verifier through the bundle's `ResetPasswordHelper`, sends a `TemplatedEmail` with the link, and writes the subject and body through the translator with new `reset_password.*` keys in `translations/messages+intl-icu.en.xlf`. The reset page validates the token from the URL, moves it into the session so it never sits in the browser history, shows a `RepeatedType` password field with the same `Length(min: 5, max: 128)` rule `ChangePasswordType` uses, hashes the new password, removes the request row, and signs the user out of other sessions by sending them to `security_login`. `login.html.twig` gets a link to the request page under the password field.

This project ships its schema as two committed SQLite files, `data/database.sqlite` and `data/database_test.sqlite`, with `DATABASE_URL` for the test environment set in `.env.test`, so the agent runs `bin/console doctrine:schema:update --force` in both environments and commits the updated files along with the entity. Tests go in `tests/Controller/ResetPasswordControllerTest.php` in the style of `UserControllerTest`: `WebTestCase`, `submitForm`, `assertResponseRedirects`. One test requests a reset for `jane_admin`'s address, reads the token out of the message the mailer test helpers captured, follows the link, submits a new password and signs in with it through `/en/login`. Others assert that an unknown address gets the same redirect and no email, that an expired or tampered token is refused, and that a used token cannot be used twice. Before pushing, the agent runs `vendor/bin/phpunit`, `vendor/bin/phpstan analyze`, `php-cs-fixer check --diff` and the `lint:yaml`, `lint:twig`, `lint:xliff`, `lint:translations`, `lint:container` and `doctrine:schema:validate` commands from `.github/workflows/lint.yaml`.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add a password reset flow to this Symfony app and open a pull request. Read composer.json, config/packages/security.yaml, config/packages/mailer.yaml, config/routes.yaml, config/services.yaml, src/Controller/SecurityController.php, src/Controller/UserController.php, src/Form/ChangePasswordType.php, src/Entity/User.php, src/Repository/UserRepository.php, src/EventSubscriber/CommentNotificationSubscriber.php, templates/security/login.html.twig, tests/Controller/UserControllerTest.php, .env.test and .github/workflows/lint.yaml first. Require symfonycasts/reset-password-bundle, run make:reset-password, then adapt the generated code: put the routes under the /{_locale} prefix, name the new password form ResetPasswordType, send from %app.notifications.email_sender% through MailerInterface, and put every user-facing string in translations/messages+intl-icu.en.xlf. The request page must answer the same way for known and unknown emails. Add a forgotten-password link to login.html.twig. Update data/database.sqlite and data/database_test.sqlite with doctrine:schema:update --force and commit them. Write tests/Controller/ResetPasswordControllerTest.php covering the full flow with a login afterwards, an unknown email, an expired or tampered token and a token used twice. Run vendor/bin/phpunit, vendor/bin/phpstan analyze, php-cs-fixer check --diff and the lint commands from lint.yaml, and paste the results in the pull request. Do not change the login form's fields or the ChangePasswordType flow.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request that adds the bundle to `composer.json` and `composer.lock`, `config/packages/reset_password.yaml`, the `ResetPasswordRequest` entity and repository, `ResetPasswordController`, the form types, the templates under `templates/reset_password/`, new translation keys, the test file, and the two regenerated SQLite files. It edits `login.html.twig` by one link and touches nothing in `UserController` or `ChangePasswordType`. The description lists the three routes, explains why the request page answers the same way for every address, and pastes the PHPUnit, PHPStan, php-cs-fixer and lint output.

On a repository with the demo's `Tests` and `Lint` workflows, the pull request runs `vendor/bin/phpunit` on PHP 8.4 and 8.5 across Ubuntu, macOS and Windows, and the lint job runs PHP-CS-Fixer, PHPStan, the YAML, Twig, XLIFF, translation and container linters, `doctrine:schema:validate --skip-sync` and `composer audit`, so a missing translation key or an entity mapping that does not match the committed schema fails before review.

A reviewer checks the token lifetime in `reset_password.yaml` against their policy, that the email template links to the right host, that the request page leaks nothing, and that the committed SQLite files changed only by the new table. Then they set a real `MAILER_DSN` for production, since `.env` and `mailer.yaml` disable delivery with `null://null` in dev and test.

## Run it on every Symfony app without a reset flow

A team with several Symfony applications sends one `POST /o/{org}/sessions` per repository with this prompt and that repository in `resources`. Each run reads its own `security.yaml`, user entity and mailer setup, so an app whose provider loads users by email instead of username, or one with Doctrine migrations instead of committed SQLite files, gets a flow and a migration in its own shape, and each run opens its own pull request.

Give the API key a `webhook_url` and Rush POSTs `run.completed` when each turn ends, with the `session_url` to read the pull request and the test output from.

## Why run it on Rush?

A password reset is the one authentication path an attacker can start without a password. The two properties that matter, that the request page reveals nothing about which emails exist and that a token works once and expires, are easy to state and easy to get wrong in a template edit. In a Rush sandbox the agent runs the project's own PHPUnit suite with the whole flow, including a sign-in with the new password and a second use of the same token refused, and keeps every command and its output in the run's record, so the pull request shows those properties checked rather than promised.

The change reuses what the app already has: the `auto` password hasher from `security.yaml`, `MailerInterface` and the sender parameter the comment notifier uses, the translator and the Bootstrap form theme. The only new dependency is the bundle the Symfony maker itself generates code for. The same request works on any Symfony app with a form login and a Doctrine user entity.

## Frequently asked questions

### Why does the request page answer the same way for an unknown email?

So the form does not say whether an account exists. The controller redirects to the check-email page for every address and sends mail only when `UserRepository::findOneByEmail` finds a user. The test for the unknown case asserts the redirect and that no message was sent.

### Does this change how signed-in users change their password?

No. `UserController::changePassword` and `ChangePasswordType` stay as they are. The reset flow is a separate controller for people who cannot sign in, and the new form type has its own name so the two do not collide.

### Why are the SQLite files in the pull request?

symfony/demo commits `data/database.sqlite` and `data/database_test.sqlite` and has no migrations directory, so the new `reset_password_request` table has to be in those files for the app and the tests to run. On a project with Doctrine migrations the agent writes a migration instead and leaves the database alone.

### How long is a reset link valid?

The bundle's default lifetime is set in `config/packages/reset_password.yaml` and the agent keeps that default. The reviewer changes the value there, and the expired-token test shows what a user sees when a link has lapsed.

### Will the email go out in development?

Not by default. `.env` sets `MAILER_DSN=null://null` and `mailer.yaml` forces the null transport in dev and test, so the message is composed and captured but not delivered. Set a real DSN in `.env.local` to see it arrive.

## More Symfony jobs

- [Schedule Posts for Later in a Symfony App from a Linear Issue](https://getrush.ai/run/add-post-scheduling/symfony/)
- [Add Rate Limiting to a Symfony App](https://getrush.ai/run/add-rate-limiting/symfony/)
- [Add Related Posts to a Symfony Blog](https://getrush.ai/run/add-related-posts/symfony/)

## The same job on other stacks

- [Add Password Reset to an AdonisJS App](https://getrush.ai/run/add-password-reset/adonisjs/)
- [Add a Password Reset API to a Django REST Framework Project](https://getrush.ai/run/add-password-reset/django-rest-framework/)
- [Add Password Reset to a Fastify API](https://getrush.ai/run/add-password-reset/fastify/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
