This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
Go to file
Fabien Potencier 90a7fa0ca1 minor #14032 [SecurityBundle] UserPasswordEncoderCommand: Improve & simplify the command usage (ogizanagi)
This PR was squashed before being merged into the 2.7 branch (closes #14032).

Discussion
----------

[SecurityBundle] UserPasswordEncoderCommand: Improve & simplify the command usage

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #13988
| License       | MIT

Overlaps #14017 (might replace or follow it) . Sorry if it is considered as a duplicate, but the debate has evolved, and I think the arguments ordering isn't the best nor single way to improve this command usage anymore.
Thank you @saro0h for having considered the mentioned issues and spent time on it.

# Salt option & salt generation

Thanks to @ircmaxell & @inanimatt, we came to the conclusion that the use-cases for the `salt` option/argument are pretty arguable. So I suggest to get rid of it: **a salt will always be generated by the command.**

### Generated salt
The generated salt is now in the Table output:
`security:encode-password test -n`
![screenshot 2015-03-30 a 21 38 21](https://cloud.githubusercontent.com/assets/2211145/6905081/d96f3ea4-d725-11e4-9b7c-83de8a75f28e.PNG)

The "Generated salt" row and the last comment about the salt aren't present if the new `empty-salt` option is provided (see below).

# New empty-salt option

As some encoders might generate their own built-in salts (like the `BCryptPasswordEncoder`) and some custom encoders could do the same (or not require a salt at all), I suggest a new option: `empty-salt`.
This option will not provide any salt to the configured encoder, which will generate its own, then.

With the interactive way, the user will always be asked confirmation for the salt generation if the `empty-salt` option isn't set:

`security:encode-password password`
![screenshot 2015-03-30 a 21 38 43](https://cloud.githubusercontent.com/assets/2211145/6905072/c53df984-d725-11e4-9a1a-81c3a363b5fe.PNG)

### bcrypt encoder

As the `BCryptPasswordEncoder` is shipped with the security component, and listening to @inanimatt valuable comments in #13988, I introduced a second commit (0cdb546) making an exception for the `bcrypt` encoder, and always set the `empty-salt` option with it.
We're aware that's not ideal from a OO design perspective, but far better from a DX one. If not desired, I will revert it.
Anyway I think https://github.com/symfony/symfony/issues/13988#issuecomment-85068382 and other comments about the `PasswordEncoder` API and salt generation should be considered for 3.0.

A note is added when bcrypt encoder is detected without the `empty-salt` option:
`security:encode-password password "Custom\Class\Bcrypt\User" -n`
![screenshot 2015-03-30 a 19 46 36](https://cloud.githubusercontent.com/assets/2211145/6905066/b53edb52-d725-11e4-87e9-636bf177299a.PNG)

# Default user-class

The default `user-class` is set to `Symfony\Component\Security\Core\User\User`.
I think this makes sense, as in the previous version of the command, the Symfony\Component\Security\Core\User\User was configured in the setAutocompleterValues and set the $value to Symfony\Component\Security\Core\User\User if null.

Asking the question to the user with the interactive command would have been useful only if the user was able to pick one encoder from a choice list.

# Arguments order / make arguments options

When we had both `salt` and `user-class` as arguments, the command looked like:
```sh
security:encode-password [password] [user-class] [salt]
```
All arguments were optional, for the interactive command purpose (The command asked the user for missing arguments).
But, as they were arguments, we had to provide each of them in the proper order. That meant we couldn't provide a salt without defining the optional user-class.
So I suggested using options instead of arguments for both user-class & salt.

But as the `salt` option/argument is removed, now I don't feel the need for the `user-class` to be an option.
Indeed, the new command short version will look like the following:
```sh
#Default user-class: Symfony\Component\Security\Core\User\User
security:encode-password password

#Another user-class:
security:encode-password password "AppBundle\Model\User"
```

Making the user-class an option IMO isn't a necessity anymore, and will only lengthen the command:
```sh
security:encode-password password --user-class="AppBundle\Model\User"
```

## Bonus:
- [The new command documentation](https://cloud.githubusercontent.com/assets/2211145/6845201/48a66382-d3b2-11e4-8227-b799215a2783.PNG). Thanks to @javiereguiluz.
- [Full interactivity output](https://cloud.githubusercontent.com/assets/2211145/6906381/d7753ce4-d72e-11e4-8547-2ef35c6257e9.PNG)

Commits
-------

b3f6340 [SecurityBundle] UserPasswordEncoderCommand: Improve & simplify the command usage
2015-04-07 12:27:23 +02:00
src/Symfony minor #14032 [SecurityBundle] UserPasswordEncoderCommand: Improve & simplify the command usage (ogizanagi) 2015-04-07 12:27:23 +02:00
.editorconfig Add EditorConfig File 2012-06-16 14:08:15 +02:00
.gitignore CS: general fixes 2015-03-25 00:47:08 +01:00
.php_cs CS: general fixes 2015-03-25 00:47:08 +01:00
.travis.sh [travis] Do no tar in // 2015-03-13 13:47:20 +01:00
.travis.yml [Debug] Add debug extension to the test suite 2015-04-03 17:33:45 +02:00
CHANGELOG-2.2.md Merge branch '2.2' into 2.3 2013-12-03 15:51:26 +01:00
CHANGELOG-2.3.md updated CHANGELOG for 2.3.27 2015-04-01 16:27:49 +02:00
CHANGELOG-2.4.md updated CHANGELOG for 2.4.9 2014-09-03 11:50:09 +02:00
CHANGELOG-2.5.md updated CHANGELOG for 2.5.10 2015-02-02 10:26:02 +01:00
CHANGELOG-2.6.md updated CHANGELOG for 2.6.6 2015-04-01 18:55:18 +02:00
composer.json [PhpUnitBridge] do not replace but require-dev in symfony/symfony 2015-03-07 17:28:03 +01:00
CONTRIBUTING.md [2.3] Update CONTRIBUTING.md 2015-02-24 10:01:10 +01:00
CONTRIBUTORS.md update CONTRIBUTORS for 2.3.27 2015-04-01 16:28:11 +02:00
LICENSE Updated copyright to 2015 2015-01-01 13:56:52 +01:00
phpunit.xml.dist Merge branch '2.3' into 2.6 2015-02-24 12:52:21 +01:00
README.md Update README.md to min PHP 5.3.9 2015-01-10 19:20:22 +01:00
UPGRADE-2.1.md Remove aligned '=>' and '=' 2014-10-26 08:30:58 +01:00
UPGRADE-2.2.md Merge branch '2.3' into 2.5 2014-10-01 07:50:18 +02:00
UPGRADE-2.3.md [Doc] Use Markdown syntax highlighting 2014-10-01 07:38:33 +02:00
UPGRADE-2.4.md [Form] Changed (Number|Integer)ToLocalizedStringTransformer::reverseTransform() to do rounding 2013-08-01 17:19:11 +02:00
UPGRADE-2.5.md Merge branch '2.5' into 2.6 2015-01-05 21:59:13 +01:00
UPGRADE-2.6.md Fix grammar 2014-12-30 09:24:50 +01:00
UPGRADE-2.7.md fix upgrade readme syntax 2015-04-05 23:36:11 +02:00
UPGRADE-3.0.md feature #13717 Deprecated precision option in favor of scale (WouterJ) 2015-04-03 19:01:25 +02:00

README

What is Symfony?

Symfony is a PHP 5.3 full-stack web framework. It is written with speed and flexibility in mind. It allows developers to build better and easy to maintain websites with PHP.

Symfony can be used to develop all kind of websites, from your personal blog to high traffic ones like Dailymotion or Yahoo! Answers.

Requirements

Symfony is only supported on PHP 5.3.9 and up.

Be warned that PHP 5.3.16 has a major bug in the Reflection subsystem and is not suitable to run Symfony (https://bugs.php.net/bug.php?id=62715)

Installation

The best way to install Symfony is to download the Symfony Standard Edition available at http://symfony.com/download.

Documentation

The "Quick Tour" tutorial gives you a first feeling of the framework. If, like us, you think that Symfony can help speed up your development and take the quality of your work to the next level, read the official Symfony documentation.

Contributing

Symfony is an open source, community-driven project. If you'd like to contribute, please read the Contributing Code part of the documentation. If you're submitting a pull request, please follow the guidelines in the Submitting a Patch section and use Pull Request Template.

Running Symfony Tests

Information on how to run the Symfony test suite can be found in the Running Symfony Tests section.