vendredi 31 août 2018

Change ways to retrieve user data - Password Broker - Laravel 5.1

First of all, sorry for my bad English

Currently I use PasswordBroker facade to reset password of users. Below is script to do:

use Password; // Facade: Illuminate\Auth\Passwords\PasswordBroker
...
...
$userCredentials = $request->only(
    'email', 'password', 'password_confirmation', 'token'
);

$response = Password::reset(
    $userCredentials,
    function (User $user, $password) {
        $user->password = $password;
        $user->save();
    }
);

With correct email, token and valid password, all users can reset their password easily.

New my system had been updated. All emails in users table has been encrypted (AES_ENCRYPT), so I need to make some changes to apply.

Here is getUser method of Password facade

public function getUser(array $credentials)
{
    $credentials = Arr::except($credentials, ['token']);

    $user = $this->users->retrieveByCredentials($credentials);

    if ($user && ! $user instanceof CanResetPasswordContract) {
        throw new UnexpectedValueException('User must implement CanResetPassword interface.');
    }

    return $user;
}

I need some where criteria like

$user->where(
    DB::raw("AES_DECRYPT(email, 'encryption key')"),
    $userEmail
);

How to apply the criteria without change original source code of Laravel?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire