fix(BE): login
This commit is contained in:
parent
c02a19a9b4
commit
e4a8a7605a
1 changed files with 17 additions and 15 deletions
|
@ -4,7 +4,9 @@ namespace App\Actions\Fortify;
|
|||
|
||||
use App\Models\User;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Throwable;
|
||||
|
||||
class LoginUser
|
||||
|
@ -21,25 +23,25 @@ class LoginUser
|
|||
try {
|
||||
$user = User::where('login', $userInfo['username'])->first();
|
||||
if ($user) {
|
||||
$password = User::where('pass',md5($userInfo['password']))->orWhere('pass',Hash::make($userInfo['password']))->first();
|
||||
if ($password) {
|
||||
$user['role'] = ($user->getRoleNames())->first();
|
||||
$password = $user->getAuthPassword();
|
||||
// Check if the stored password is an MD5 hash
|
||||
if (strlen($password) === 32 && ctype_xdigit($password)) {
|
||||
if (md5($userInfo['password']) === $password) {
|
||||
return $user;
|
||||
}
|
||||
} else {
|
||||
if (Hash::check($userInfo['password'], $password)) {
|
||||
return $user;
|
||||
}
|
||||
$user['role'] = ($user->getRoleNames())->first();
|
||||
$password = $user->getAuthPassword();
|
||||
if (strlen($password) === 32 && ctype_xdigit($password)) {
|
||||
if (hash_equals($password, md5($userInfo['password']))) {
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
if (Hash::check($userInfo['password'], $password)) {
|
||||
return $user;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch (Throwable $e) {
|
||||
report($e);
|
||||
return $e;
|
||||
Log::error('Login error: ' . $e->getMessage());
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue