-
Notifications
You must be signed in to change notification settings - Fork 793
crypt() salt parameter is no longer optional #1533
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
Comments
Indeed, the info about that parameter being optional needs to be changed. We prefer the wording "Prior to PHP 8.0.0, …" The deprecation of passing null is not specifc to this function, but a general change. The salt parameter never was nullable, so prior to PHP 8.1.0, passing |
Thanks for the fast reply.
Fine with me 👍
Duh. You're right of course... Silly me 😳
crypt() returns |
An empty |
My point is that this is a change in behavior in PHP 8 compared to 7.4 and older. Assuming this was intentional, it should be documented. Otherwise it's a bug that should be fixed... echo crypt('password', ''); Output for 8.x Doc currently says |
Oh, right, the behavior for an empty string passed as |
For the record, I know it's a weak encryption and that password_hash() should be used instead; I am actually in the process of updating legacy code to achieve that. I'm just trying to maintain backwards-compatibility if possible, but it looks like it may not be the case. |
Like I said, I'm not sure whether that issue will be fixed. However, you can work around this in userland by providing an own OTOH, you may be better off switching to the |
@cmb69 The change is intentional. The user should generate an |
Thanks both for following up. I was pretty sure this was an intentional change (which makes perfect sense), the only problem is that it was not reflected in the documentation. It may be a good idea to explain |
From manual page: https://php.net/function.crypt
This manual page is somewhat out-of-date, regarding the $salt parameter.
PHP >= 8.0 throws PHP Warning: Uncaught ArgumentCountError: crypt() expects exactly 2 arguments, 1 given. The mention that the parameter is mandatory in PHP 8 is mentioned further down (in the changelog section), IMO it would be worth rephrasing along the lines of
Until PHP 8, the salt parameter was optional. However...
Additionally, the function returns
*0
instead of a CRYPT_STD_DES hash as it did with PHP 7.x when given a null salt. PHP 8.1 throws Deprecated: crypt(): Passing null to parameter #2 ($salt) of type string is deprecated (8.0 does not even throw a warning) - this is a bit more than deprecation...The text was updated successfully, but these errors were encountered: