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.
35 lines
929 B
35 lines
929 B
<?php
|
|
|
|
namespace App\Auth;
|
|
|
|
use Illuminate\Auth\EloquentUserProvider;
|
|
use Illuminate\Contracts\Auth\Authenticatable;
|
|
|
|
class CustomUserProvider extends EloquentUserProvider
|
|
{
|
|
public function validateCredentials(Authenticatable $user, array $credentials): bool
|
|
{
|
|
$plain = $credentials['password'];
|
|
$hashed = $user->getAuthPassword();
|
|
|
|
if ($this->isBcryptHash($hashed)) {
|
|
if ($this->hasher->check($plain, $hashed)) {
|
|
return true;
|
|
}
|
|
} else {
|
|
if (md5($plain) === $hashed) {
|
|
// Upgrade lên bcrypt
|
|
$user->password = $this->hasher->make($plain);
|
|
$user->save();
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
protected function isBcryptHash($hashedPassword): bool
|
|
{
|
|
return password_get_info($hashedPassword)['algo'] === PASSWORD_BCRYPT;
|
|
}
|
|
}
|
|
|