Symfony Security Bundle - MiguelFieira/AMO-HANDBOEK GitHub Wiki

In this guide we'll walk you through using Symfony's own Security Bundle to create users for your application.

First, start off with installing the Security Bundle.

composer require symfony/security-bundle

Then create a User entity, but NOT via the make:entity, but via make:user. If you cannot run the command make:user, try installing the MakerBundle.

composer require symfony/maker-bundle --dev

The make:user wizard will proceed to ask you about storing the user in the database, which property of the user should be identifiable (should be logged in with) and if the user requires a password.

Now, much of the configuration has already been done for you, but if you want to, you can see what can be configured here.

Login Form

You can create a login form by running the make:auth command.

On the question What style of authentication do you want? [Empty authenticator]:, enter 1 for the Login form authenticator.

Usually we also want a logout URL, so at Do you want to generate a '/logout' URL? (yes/no) [yes]:, we enter yes.

Check src/Security/LoginFormAuthenticator.php and make sure that onAuthenticationSuccess() returns a RedirectResponse object.

// an example redirect
return new RedirectResponse($this->urlGenerator->generate('index'));

If you want to know about additional Login form configuration, you can look at this page.

Registration form

To make a registration form you could manually create a form, but the MakerBundle also provides you with a handy make:registration-form command.

Reset password

SymfonyCasts has a bundle for making reset password features.

composer require symfonycasts/reset-password-bundle

Now you can do make:reset-password and watch the magic happen.