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.
32 lines
815 B
32 lines
815 B
<?php
|
|
|
|
namespace App\Auth\Providers;
|
|
|
|
use Illuminate\Auth\EloquentUserProvider;
|
|
use Illuminate\Contracts\Auth\Authenticatable;
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
class MD5UserProvider extends EloquentUserProvider
|
|
{
|
|
public function validateCredentials(Authenticatable $user, array $credentials)
|
|
{
|
|
$plain = $credentials['password'];
|
|
$hashed = $user->getAuthPassword();
|
|
|
|
// Nếu là Bcrypt → dùng bình thường
|
|
if (!Hash::needsRehash($hashed)) {
|
|
return Hash::check($plain, $hashed);
|
|
}
|
|
|
|
// Nếu là MD5 → kiểm tra tay
|
|
if (md5($plain) === $hashed) {
|
|
// Tự động upgrade
|
|
$user->password = Hash::make($plain);
|
|
$user->save();
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|