fix(BE): login

This commit is contained in:
Michael 2025-06-25 17:08:28 +02:00
parent c02a19a9b4
commit e4a8a7605a

View file

@ -4,7 +4,9 @@ namespace App\Actions\Fortify;
use App\Models\User; use App\Models\User;
use Exception; use Exception;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Log;
use Throwable; use Throwable;
class LoginUser class LoginUser
@ -21,25 +23,25 @@ class LoginUser
try { try {
$user = User::where('login', $userInfo['username'])->first(); $user = User::where('login', $userInfo['username'])->first();
if ($user) { if ($user) {
$password = User::where('pass',md5($userInfo['password']))->orWhere('pass',Hash::make($userInfo['password']))->first(); $user['role'] = ($user->getRoleNames())->first();
if ($password) { $password = $user->getAuthPassword();
$user['role'] = ($user->getRoleNames())->first(); if (strlen($password) === 32 && ctype_xdigit($password)) {
$password = $user->getAuthPassword(); if (hash_equals($password, md5($userInfo['password']))) {
// Check if the stored password is an MD5 hash return $user;
if (strlen($password) === 32 && ctype_xdigit($password)) {
if (md5($userInfo['password']) === $password) {
return $user;
}
} else {
if (Hash::check($userInfo['password'], $password)) {
return $user;
}
} }
} }
if (Hash::check($userInfo['password'], $password)) {
return $user;
}
return null;
} }
return null;
} catch (Throwable $e) { } catch (Throwable $e) {
report($e); Log::error('Login error: ' . $e->getMessage());
return $e;
return null;
} }
} }
} }