Mapping Model User authentication to Sunday English

master
sundayenglish 4 weeks ago
parent 48b001d052
commit 7be7c2f278
  1. 10
      app/Auth/CustomUserProvider.php
  2. 10
      app/Auth/PassportUserRepository.php
  3. 4
      app/Providers/AuthServiceProvider.php

@ -16,15 +16,15 @@ class CustomUserProvider extends EloquentUserProvider
if ($this->isBcryptHash($hashed)) {
// Use the hasher to verify the password
if ($this->hasher->check($plain, $hashed)) {
return true;
return true;
}
} else {
// Fallback for legacy MD5 hashes
if (md5($plain) === $hashed) {
// Upgrade the password to bcrypt
$user->password = $this->hasher->make($plain);
$user->save();
return true;
// Upgrade the password to bcrypt
$user->password = $this->hasher->make($plain);
$user->save();
return true;
}
}

@ -25,16 +25,16 @@ class PassportUserRepository extends UserRepository
// Avoid Hash::check() error with non-bcrypt hashes
if ($this->isBcryptHash($user->password)) {
if (Hash::check($password, $user->password)) {
return new User($user->id);
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();
// Upgrade password to bcrypt
$user->password = Hash::make($password);
$user->save();
return new User($user->id);
return new User($user->id);
}
}

@ -29,8 +29,8 @@ class AuthServiceProvider extends ServiceProvider
// Use custom Passport user repository for API login
$this->app->afterResolving(AuthorizationServer::class, function ($server) {
$grant = new \League\OAuth2\Server\Grant\PasswordGrant(
app(PassportUserRepository::class), // Custom Passport user repository
app(RefreshTokenRepository::class)
app(PassportUserRepository::class), // Custom Passport user repository
app(RefreshTokenRepository::class)
);
$grant->setRefreshTokenTTL(new DateInterval('P1M')); // 1 month refresh token

Loading…
Cancel
Save