4external's avatar

Cannot properly register new Hasher

Hi!

Have this code in App/Providers/SHA512HashServiceProvider.php

    public function register() {

        $this->app->singleton('hash', function () {
            abort(200, 'in singleton');

            return new SHA512Hasher();
        });

        abort(200, 'after clojure');
    }

abort on "after clojure" is executed, but not in clojure, of course with commenting * abort(200, 'after clojure'); *

And password checking with bcrypt, not my sha512.

What i doing wrong?

Another code in app.php

/*
|--------------------------------------------------------------------------
| Register Service Providers
|--------------------------------------------------------------------------
|
| Here we will register all of the application's service providers which
| are used to bind services into the container. Service providers are
| totally optional, so you are not required to uncomment this line.
|
*/

// $app->register(App\Providers\AppServiceProvider::class);
$app->register(App\Providers\AuthServiceProvider::class);
// $app->register(App\Providers\EventServiceProvider::class);
$app->register(App\Providers\SHA512HashServiceProvider::class);

UPDATE: After debug in $this->app->singleton i found that

17-Jan-2018 08:42:23 log abstarct=League\OAuth2\Server\AuthorizationServer log backtrace=
17-Jan-2018 08:42:23 log abstarct=League\OAuth2\Server\ResourceServer log backtrace=
17-Jan-2018 08:42:23 log abstarct=Illuminate\Database\Connection log backtrace=
*** 17-Jan-2018 08:42:23 SHA512 REG ***
Registering my hasher ***17-Jan-2018 08:42:23 log abstarct=hash log backtrace= ***
17-Jan-2018 08:42:23 log abstarct=encrypter log backtrace=
17-Jan-2018 08:42:23 log abstarct=encrypter log backtrace=
Framework registering Application\registerHashBindings *** 17-Jan-2018 08:42:23 log abstarct=hash log backtrace= ***
Framework registering Illuminate\Hashing\HashServiceProvider *** 17-Jan-2018 08:42:23 log abstarct=hash log backtrace=****
17-Jan-2018 08:42:23 log abstarct=Psr\Http\Message\ServerRequestInterface log backtrace=

HashServiceProvider is BCrypt registration, so this is rewrite my hashing.

0 likes
1 reply
4external's avatar
4external
OP
Best Answer
Level 1

Ok

https://github.com/krisanalfa/lumen-jwt/issues/40#issuecomment-324241363

unfortunately Lumen makes you unable to change the default hasher. You can see why here. Lumen will automatically resolve hash instance via this method. It's not registered at the first time (boot), but when it's needed, it will resolved automagically. That's why this framework is very fast. Anyway, in another words: No matter how you override the hash instance via service provider, it will NOT working, the default Laravel hash will be used.

Please or to participate in this conversation.