-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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
Conversation
|
||
$encoded = $encoder->encodePassword($plainPassword, $user->getSalt()); | ||
|
||
return $encoded; |
There was a problem hiding this comment.
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()
.
So you don't think that this comment #11299 (comment) is a great idea ? (just not repeat "password") |
@jakzal I've update your comments. Please review it and tell me if I have to change anything else. |
@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); |
👍 for @javiereguiluz comment, password is redundant. @Nek- I think |
* | ||
* @author Ariel Ferrandini <arielferrandini@gmail.com> | ||
*/ | ||
class PasswordEncoderService |
There was a problem hiding this comment.
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).
I forgot to implements the PasswordEncoderServiceInterface. @jakzal I added the Service prefix in order to prevent collision with PasswordEncoderInterface in the same namespace. |
Do we need an interface here? It's a helper class and is unlikely to be overriden. How about calling the class |
@jakzal 👍 to the class name |
@jakzal changes made, and also passed the php-cs-fixer hope everything it's ok now |
I like this implementation. @aferrandini we should also get a PR (or at least an issue) on |
@waverryan of course 👍 |
@weaverryan I added a PR to the symfony/symfony-docs repo with documentation. |
@aferrandini you're on fire! |
@aferrandini docs link point to the current repository (symfony/symfony). I think you should enter the full url |
@ggam updated |
👍 |
Thank you @aferrandini. |
…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
…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
This new service siplifies the way to encode a password. Just get the
security.password_encoder
service and encode theUser
password.