$nip, 'password_submitted' => $password, ]; // Try to find user in UserDosen $userDosen = UserDosen::where('nip', $nip)->first(); if ($userDosen) { $result['found_in'] = 'users_dosen'; $result['user_name'] = $userDosen->nama; $result['password_hash'] = substr($userDosen->password, 0, 20) . '...'; $result['password_matches'] = Hash::check($password, $userDosen->password); return response()->json($result); } // Try to find user in UserStaff $userStaff = UserStaff::where('nip', $nip)->first(); if ($userStaff) { $result['found_in'] = 'users_staff'; $result['user_name'] = $userStaff->nama; $result['password_hash'] = substr($userStaff->password, 0, 20) . '...'; $result['password_matches'] = Hash::check($password, $userStaff->password); return response()->json($result); } $result['found_in'] = null; $result['message'] = 'User not found with NIP: ' . $nip; return response()->json($result); } /** * List all users for debugging */ public function listUsers() { $dosen = UserDosen::select('id', 'nama', 'nip', 'role')->limit(5)->get(); $staff = UserStaff::select('id', 'nama', 'nip', 'role')->limit(5)->get(); return response()->json([ 'dosen_count' => UserDosen::count(), 'staff_count' => UserStaff::count(), 'sample_dosen' => $dosen, 'sample_staff' => $staff, ]); } /** * Check password status for UserStaff */ public function checkStaffPasswords() { $staffUsers = UserStaff::limit(10)->get(); $result = [ 'total_staff' => UserStaff::count(), 'checked_count' => count($staffUsers), 'records' => [], ]; foreach ($staffUsers as $staff) { $passwordField = $staff->password; $isHashed = strpos($passwordField, '$2') === 0; $record = [ 'id' => $staff->id, 'nip' => $staff->nip, 'nama' => $staff->nama, 'password_preview' => substr($passwordField, 0, 30) . '...', 'is_hashed' => $isHashed, 'password_algo' => $isHashed ? 'Bcrypt' : 'Plain Text', ]; // If plain text, test if it matches common password if (!$isHashed) { $record['is_plain_text'] = true; $record['test_match_password123'] = ($passwordField === 'password123'); } $result['records'][] = $record; } return response()->json($result); } /** * Hash all UserStaff passwords to 'password123' */ public function hashStaffPasswords() { $count = 0; $staffUsers = UserStaff::all(); $result = [ 'message' => 'Hashing staff passwords to password123', 'count' => 0, 'records' => [], ]; foreach ($staffUsers as $staff) { $staff->password = Hash::make('password123'); $staff->save(); $count++; $result['records'][] = [ 'nip' => $staff->nip, 'nama' => $staff->nama, 'status' => 'hashed', ]; } $result['count'] = $count; $result['success'] = true; $result['message'] = "✅ Successfully hashed {$count} staff passwords to 'password123'"; return response()->json($result); } /** * Test programmatic login for UserStaff */ public function testStaffLogin() { // Find a staff user $staff = UserStaff::first(); if (!$staff) { return response()->json(['error' => 'No staff users found'], 404); } // Try to login programmatically try { session()->regenerate(); Auth::guard('web')->login($staff); return response()->json([ 'success' => true, 'message' => 'Staff login successful', 'nip' => $staff->nip, 'nama' => $staff->nama, 'authenticated' => Auth::check(), 'user_id' => Auth::id(), 'redirect_url' => route('welcome'), ]); } catch (\Exception $e) { return response()->json([ 'success' => false, 'error' => $e->getMessage(), ], 500); } } }