You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

48 lines
1.3 KiB

<?php
namespace App\Passport;
use Laravel\Passport\Bridge\User;
use Laravel\Passport\Bridge\UserRepository as PassportUserRepository;
use League\OAuth2\Server\Entities\ClientEntityInterface;
use Illuminate\Support\Facades\Hash;
use App\Models\GKUser;
class CustomUserRepository extends PassportUserRepository
{
/**
* Retrieve a user entity by user credentials.
*
* @param string $username
* @param string $password
* @param string $grantType
* @param ClientEntityInterface $client
* @return User|null
*/
public function getUserEntityByUserCredentials($username, $password, $grantType, ClientEntityInterface $client)
{
$user = GKUser::where('email', $username)->first();
if (! $user) {
return;
}
$hashed = $user->password;
// Check if the password is already hashed using bcrypt
if (!Hash::needsRehash($hashed)) {
if (!Hash::check($password, $hashed)) {
return;
}
}
// If the password is hashed using MD5, verify and upgrade to bcrypt
elseif (md5($password) !== $hashed) {
return;
} else {
$user->password = Hash::make($password);
$user->save();
}
return new User($user->getAuthIdentifier());
}
}