W
W
Well_Done2020-06-25 18:29:28
Laravel
Well_Done, 2020-06-25 18:29:28

Laravel how to correctly change hashing during authentication?

Hello!
I am working on a small project. I decided to do it on Laravel, and at the same time study this framework.
There are still misunderstandings in many things.
There is already a database with user data. The password storage format is different from laravel. Need this type: md5(bin2hex(str))
Registration is not required. But there is a problem with the login. Found one of the options, changed the method here:
vendor/laravel/framework/src/Illuminate/Auth/EloquentUserProvider.php

public function validateCredentials(UserContract $user, array $credentials)
    {
        $plain = $credentials['password'];

        if (md5(bin2hex($plain)) == $user->getAuthPassword()) {
            return true;
        } else {
            return false;
        }
        // return $this->hasher->check($plain, $user->getAuthPassword());
    }


Of course, it works now, but as far as we know, you cannot change files in the /vendor/ folder.
Tell me how you can correctly implement the same thing, but without violating the framework files.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2020-06-25
@New_Horizons

It may be enough to add your own hasher, implement interface methods:

use Illuminate\Contracts\Hashing\Hasher;
use Illuminate\Hashing\AbstractHasher;

class CustomHasher extends AbstractHasher implements Hasher
{}

then register it somewhere in the service provider:
app('hash')->extend('custom_hasher', function () {
  return new CustomHasher();
});

then in the config file config/hashing.php change the driver to custom_hasher
Well, something like that...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question