Skip to content
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

[5.7] Hash::check breaks all apps with legacy hash #25586

Closed
kamui545 opened this issue Sep 12, 2018 · 9 comments
Closed

[5.7] Hash::check breaks all apps with legacy hash #25586

kamui545 opened this issue Sep 12, 2018 · 9 comments

Comments

@kamui545
Copy link
Contributor

kamui545 commented Sep 12, 2018

>>> Hash::check('s3cr3t', '$1$0590adc6$WVAjBIam8sJCgDieJGLey0');
RuntimeException with message 'This password does not use the Bcrypt algorithm.'

Use case: We have applications with sha1 AND bcrypt passwords.
On successful login, an event is triggered to update the hash stored in DB to the stronger hash algorithm.

Since the 5.7 update, all users with legacy passwords are not able to login anymore.

Please, reconsider this check in the Hash::check method or make it optional, it should be consistent with how password_verify() works.

Password hashing is not backward compatible nor future proof anymore...

Breaking changes introduced in: #24162 / #24178
Related issues: https://github.com/laravel/docs/issues/4509, #25468, #25458

@kamui545
Copy link
Contributor Author

kamui545 commented Sep 16, 2018

In the meantime, for those stuck and who still would like to upgrade, here's how:

Create app/Hashing/BcryptHasher.php:

<?php

namespace App\Hashing;

use Illuminate\Hashing\BcryptHasher as BaseHasher;

class BcryptHasher extends BaseHasher
{
    /**
     * Check the given plain value against a hash.
     *
     * @param  string  $value
     * @param  string  $hashedValue
     * @param  array  $options
     * @return bool
     */
    public function check($value, $hashedValue, array $options = [])
    {
        if (strlen($hashedValue) === 0) {
            return false;
        }

        return password_verify($value, $hashedValue);
    }
}

Then in your AppServiceProvider add:

app('hash')->extend('legacy-bcrypt', function () {
    return new BcryptHasher($this->app['config']['hashing.bcrypt'] ?? []);
});

And set 'driver' => 'legacy-bcrypt' in config/hashing.php

@crynobone
Copy link
Member

I wonder why do we need to use Hash::check() for authentication verification if at the end we plan to support multiple hashing algorithm; bcrypt and argon1.

Shouldn't we respect whatever hashing used in the password as long as password_verify() can verify the password?

@crynobone
Copy link
Member

This has been fixed in 5.7.4

@laurencei
Copy link
Contributor

Thanks @crynobone !

Closing as this issue has been resolved.

@mnabialek
Copy link
Contributor

@crynobone See me comment in #25677 why we should still use Hash::check() if we don't want to break existing apps that uses custom hasher.

@kamui545
Copy link
Contributor Author

Can we re-open this now that the partial fix has been reverted?

@laurencei laurencei reopened this Sep 21, 2018
@robinvdvleuten
Copy link
Contributor

This also breaks your app if the user does not have a password set. This wasn't the case before Laravel 5.7.

@donovanhare
Copy link
Contributor

#25468 has been merged, we await a new release...

@laurencei
Copy link
Contributor

Closing as this issue has been resolved (again).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants