mardi 4 juillet 2017

How to disable password hash algorithm of laravel 5.4 Auth and apply customized password encrypting method?

I am trying to integrating laravel 5.4 auth login. I am using mongoDB database. Collection name is user authenticated field is usrName and usrPassword. At-present my problem is I need to change the default password hash algorithm and apply customized password encrypting method. I heard it is possible when override the functions validateCredentials.

I tried some code but I don't know Am I following correct or not. Please check and help me.

LoginController.php

public function login(Request $request)
    {
        $this->validate($request, [
            'username' => 'required|max:255',
            'password' => 'required|max:255'
        ]);

        $authUser = User::where('usrName', $request->username)->first();

        if (isset($authUser)) {
            //$password = md5('aFGQ475SDsdfsaf2342' . $request->password . $authUser->usrPasswordSalt);

//dd($password); Here i am getting the correct password- 96a65063135247fef732b5901fe05d1f 

            if (Auth::attempt([$this->username() => $request->username, 'password' => $request->password])) {
                return 'logged in successfully : '.$this->username() . ' - ' . $password;
            }
            else {
                return 'oops something happend : '.$this->username() . ' - ' . $password;
            }
        }
}

app -> Providers -> CustomUserProvider.php

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use App\User;

class CustomUserProvider extends ServiceProvider
{
    public function validateCredentials(User $user, array $credentials)
    {
        $plain = $credentials['password'];
        $password = md5('aFGQ475SDsdfsaf2342' . $request->password . $user->usrPasswordSalt);

        return $this->hasher->check($plain, $user->getAuthPassword());
    }
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire