Skip to content

[DX] New service to simplify password encoding #11306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2014
Merged

[DX] New service to simplify password encoding #11306

merged 1 commit into from
Jul 25, 2014

Conversation

aferrandini
Copy link
Contributor

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #11299
License MIT
Doc PR symfony/symfony-docs#3995

This new service siplifies the way to encode a password. Just get the security.password_encoder service and encode the User password.

$encoded = $this->container->get('security.password_encoder')
    ->encodePassword($user, $plainPassword);

$user->setPassword($encoded);


$encoded = $encoder->encodePassword($plainPassword, $user->getSalt());

return $encoded;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could make it more consistent and avoid assignment, just like in the isPasswordValid().

@Nek-
Copy link
Contributor

Nek- commented Jul 5, 2014

So you don't think that this comment #11299 (comment) is a great idea ? (just not repeat "password")

@aferrandini
Copy link
Contributor Author

@jakzal I've update your comments. Please review it and tell me if I have to change anything else.

@aferrandini
Copy link
Contributor Author

@javiereguiluz we could have both methods, one for validate user password as you mention before and another to validate a password, due to could be a password not stored in the user object.

public function isPasswordValid(UserInterface $user, $encoded, $raw);

public function isUserPasswordValid(UserInterface $user, $raw);

@jakzal
Copy link
Contributor

jakzal commented Jul 5, 2014

👍 for @javiereguiluz comment, password is redundant.

@Nek- I think security.password_encoder is a name that reflects the serivce's purpose bettern than security.encoder (what kind of an encoder?). Then, the method names (encodePassword, isPasswordValid) are inline with the encoder factory, so probably what most users would expect.

*
* @author Ariel Ferrandini <arielferrandini@gmail.com>
*/
class PasswordEncoderService
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PasswordEncoder would be better. We don't use the Service suffix (it doesn't bring much value).

@aferrandini
Copy link
Contributor Author

I forgot to implements the PasswordEncoderServiceInterface.

@jakzal I added the Service prefix in order to prevent collision with PasswordEncoderInterface in the same namespace.

@jakzal
Copy link
Contributor

jakzal commented Jul 5, 2014

Do we need an interface here? It's a helper class and is unlikely to be overriden.

How about calling the class UserPasswordEncoder?

@aferrandini
Copy link
Contributor Author

@jakzal 👍 to the class name UserPasswordEncoder

@aferrandini
Copy link
Contributor Author

@jakzal changes made, and also passed the php-cs-fixer hope everything it's ok now

@weaverryan
Copy link
Member

I like this implementation. @aferrandini we should also get a PR (or at least an issue) on symfony/symfony-docs for the changes (which will shorten things!). Can you create one of those?

@aferrandini
Copy link
Contributor Author

@waverryan of course 👍

@aferrandini
Copy link
Contributor Author

@weaverryan I added a PR to the symfony/symfony-docs repo with documentation.

@weaverryan
Copy link
Member

@aferrandini you're on fire!

@ggam
Copy link

ggam commented Jul 5, 2014

@aferrandini docs link point to the current repository (symfony/symfony). I think you should enter the full url https://github.com/symfony/symfony-docs/pull/3995

@aferrandini
Copy link
Contributor Author

@ggam updated

@fabpot
Copy link
Member

fabpot commented Jul 23, 2014

👍

@fabpot
Copy link
Member

fabpot commented Jul 25, 2014

Thank you @aferrandini.

@fabpot fabpot merged commit 7bc190a into symfony:master Jul 25, 2014
fabpot added a commit that referenced this pull request Jul 25, 2014
…ndini)

This PR was merged into the 2.6-dev branch.

Discussion
----------

[DX] New service to simplify password encoding

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #11299
| License       | MIT
| Doc PR | symfony/symfony-docs#3995

This new service siplifies the way to encode a password. Just get the `security.password_encoder` service and encode the `User` password.

```php
$encoded = $this->container->get('security.password_encoder')
    ->encodePassword($user, $plainPassword);

$user->setPassword($encoded);
```

Commits
-------

7bc190a New service to simplify password encoding
weaverryan added a commit to symfony/symfony-docs that referenced this pull request Sep 1, 2014
…dini)

This PR was merged into the master branch.

Discussion
----------

[DX] New service to simplify password encoding

| Q             | A
| ------------- | ---
| Doc fix?      | no
| New docs?     | [#11306](symfony/symfony#11306)
| Applies to    | 2.6

Add documentation for symfony/symfony PR [#11306](symfony/symfony#11306)

New service to simplify password encoding.

Commits
-------

785827f New service to simplify password encoding
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX DX = Developer eXperience (anything that improves the experience of using Symfony)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants