change table

master
sundayenglish 14 hours ago
parent a05e86d7a7
commit f3dd0fb4e8
  1. 38
      app/Auth/PassportUserRepository.php

@ -3,13 +3,22 @@
namespace App\Auth;
use Laravel\Passport\Bridge\UserRepository;
use League\OAuth2\Server\Entities\ClientEntityInterface;
use Laravel\Passport\Bridge\UserRepositoryInterface;
use Laravel\Passport\Bridge\User;
use Illuminate\Support\Facades\Hash;
use League\OAuth2\Server\Entities\ClientEntityInterface;
use App\Models\User as UserModel;
class PassportUserRepository extends UserRepository
{
/**
* OAuth2.
*
* @param string $username
* @param string $password
* @param string $grantType
* @param ClientEntityInterface $clientEntity
* @return User|null
*/
public function getUserEntityByUserCredentials(
$username,
$password,
@ -22,33 +31,10 @@ class PassportUserRepository extends UserRepository
return null;
}
// Avoid Hash::check() error with non-bcrypt hashes
if ($this->isBcryptHash($user->password)) {
if (Hash::check($password, $user->password)) {
return new User($user->id);
}
} else {
// If the hash is not bcrypt, check for MD5 manually
if (md5($password) === $user->password) {
// Upgrade password to bcrypt
$user->password = Hash::make($password);
$user->save();
return new User($user->id);
}
return new User($user->getAuthIdentifier());
}
return null;
}
/**
* Check if the given hash uses the bcrypt algorithm.
*
* @param string $hashedPassword
* @return bool
*/
protected function isBcryptHash($hashedPassword): bool
{
return password_get_info($hashedPassword)['algo'] === PASSWORD_BCRYPT;
}
}

Loading…
Cancel
Save