Mapping Model User authentication to Sunday English

pull/2/head
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)) { if ($this->isBcryptHash($hashed)) {
// Use the hasher to verify the password // Use the hasher to verify the password
if ($this->hasher->check($plain, $hashed)) { if ($this->hasher->check($plain, $hashed)) {
return true; return true;
} }
} else { } else {
// Fallback for legacy MD5 hashes // Fallback for legacy MD5 hashes
if (md5($plain) === $hashed) { if (md5($plain) === $hashed) {
// Upgrade the password to bcrypt // Upgrade the password to bcrypt
$user->password = $this->hasher->make($plain); $user->password = $this->hasher->make($plain);
$user->save(); $user->save();
return true; return true;
} }
} }

@ -25,16 +25,16 @@ class PassportUserRepository extends UserRepository
// Avoid Hash::check() error with non-bcrypt hashes // Avoid Hash::check() error with non-bcrypt hashes
if ($this->isBcryptHash($user->password)) { if ($this->isBcryptHash($user->password)) {
if (Hash::check($password, $user->password)) { if (Hash::check($password, $user->password)) {
return new User($user->id); return new User($user->id);
} }
} else { } else {
// If the hash is not bcrypt, check for MD5 manually // If the hash is not bcrypt, check for MD5 manually
if (md5($password) === $user->password) { if (md5($password) === $user->password) {
// Upgrade password to bcrypt // Upgrade password to bcrypt
$user->password = Hash::make($password); $user->password = Hash::make($password);
$user->save(); $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 // Use custom Passport user repository for API login
$this->app->afterResolving(AuthorizationServer::class, function ($server) { $this->app->afterResolving(AuthorizationServer::class, function ($server) {
$grant = new \League\OAuth2\Server\Grant\PasswordGrant( $grant = new \League\OAuth2\Server\Grant\PasswordGrant(
app(PassportUserRepository::class), // Custom Passport user repository app(PassportUserRepository::class), // Custom Passport user repository
app(RefreshTokenRepository::class) app(RefreshTokenRepository::class)
); );
$grant->setRefreshTokenTTL(new DateInterval('P1M')); // 1 month refresh token $grant->setRefreshTokenTTL(new DateInterval('P1M')); // 1 month refresh token

Loading…
Cancel
Save