Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Only add salt to password_hash on PHP < 7 #16014

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

Closed
wants to merge 1 commit into from

Conversation

pierredup
Copy link
Contributor

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

The salt option for the password_hash function is deprecated since PHP 7, so it should not be added when running on PHP 7

@xabbuh
Copy link
Member

xabbuh commented Sep 30, 2015

Ignoring the salt would also work on older PHP versions. Though I think it's not expected behaviour to simply ignore the salt if it is passed. So I am 👎 on this change.

@stof
Copy link
Member

stof commented Sep 30, 2015

IMO, the behavior should be consistent: if the user pass a salt, we use it.

@pierredup
Copy link
Contributor Author

According to @ircmaxell:

"One thing has become abundantly clear to me: the salt option is
dangerous. I've yet to see a single usage of the salt option that has
been even decent. Every usage ranges from bad (passing mt_rand()
output) to dangerous (static strings) to insane (passing the password
as its own salt).

I've come to the conclusion that I don't think we should allow users
to specify the salt."

So I don't think it is a good idea to keep allowing users to pass a salt since the recommended way is to rely on the internal salt generation. And it might be promoting bad practices if we know it's not safe but still allow it

@xabbuh
Copy link
Member

xabbuh commented Sep 30, 2015

Well, we could think about deprecating the ability to pass a salt. At least, that would be less confusing and would step away from silently allow insecure usage of the encoder.

@fabpot
Copy link
Member

fabpot commented Sep 30, 2015

Indeed, doing the same as PHP password_hash function makes sense to me.

@fabpot
Copy link
Member

fabpot commented Oct 13, 2015

@pierredup Do you plan to finish this one in the near future?

@pierredup
Copy link
Contributor Author

@fabpot I'm not exactly sure what to do here.
Deprecating the option to pass a salt will have an effect on other encoders as well (like the Pbkdf2PasswordEncoder). In that case do we want to have our own salt generating function? Or how should the salt be handled for encoders that requires a salt (like pbkdf2) and others where it's not needed (like bcrypt)?

@ircmaxell
Copy link
Contributor

My suggestion would be to always generate the salt yourself. Never accept a passed in salt. There is no reason to accept a non-generated one, especially if you use standard algorithms.

This is a BC break though, so perhaps deprecate it first.

@nicolas-grekas
Copy link
Member

Replaced by #16459
Thank you @pierredup for raising the issue

nicolas-grekas added a commit that referenced this pull request Nov 5, 2015
…ordEncoder::encodePassword() (nicolas-grekas)

This PR was merged into the 2.8 branch.

Discussion
----------

[Security\Core] Deprecate passing $salt to BCryptPasswordEncoder::encodePassword()

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

Commits
-------

770bd8c [Security\Core] Deprecate passing $salt to BCryptPasswordEncoder::encodePassword()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants