/home/techb158/workloadmatch.com/includes
NameSizeModeActions
config_loader.php9630644editdlrm
CSRF_Protect.php22240644editdlrm
db_connect.php5680644editdlrm
error.php4850644editdlrm
firebase_auth.php63180644editdlrm
footer.php6170644editdlrm
forgetpassword.php108250644editdlrm
forgetpassword_Bak.php74480644editdlrm
functions.php313300644editdlrm
geoiploc.php25204350644editdlrm
header.php18040644editdlrm
hex.php10500644editdlrm
hexbin.php9420644editdlrm
login_page.php29930644editdlrm
logout.php8700644editdlrm
migrate_last_activity.php12780644editdlrm
process_login.php21190644editdlrm
psl-config-Bak.php12130644editdlrm
psl-config.php18830644editdlrm
reset.php65370644editdlrm
Edit: /home/techb158/workloadmatch.com/includes/firebase_auth.php (6318B)
['timeout' => 10, 'user_agent' => 'WorkLoadMatch/1.0']]); $response = @file_get_contents($url, false, $ctx); if ($response === false) { // Try without SSL verification as fallback $ctx = stream_context_create([ 'ssl' => ['verify_peer' => false, 'verify_peer_name' => false], 'http' => ['timeout' => 10, 'user_agent' => 'WorkLoadMatch/1.0'], ]); $response = @file_get_contents($url, false, $ctx); } if ($response === false) return null; $keys = json_decode($response, true); if (!is_array($keys)) return null; file_put_contents($cacheFile, json_encode($keys), LOCK_EX); return $keys; } function verifyFirebaseIdToken(string $idToken): ?array { $projectId = FIREBASE_PROJECT_ID; if (empty($projectId)) return null; $parts = explode('.', $idToken); if (count($parts) !== 3) return null; [$headerB64, $payloadB64, $signatureB64] = $parts; $header = json_decode(base64url_decode_firebase($headerB64), true); $payload = json_decode(base64url_decode_firebase($payloadB64), true); $signature = base64url_decode_firebase($signatureB64); if (!$header || !$payload || !$signature) return null; // Verify expiration if (isset($payload['exp']) && $payload['exp'] < time()) return null; // Verify issued-at if (isset($payload['iat']) && $payload['iat'] > time() + 300) return null; // Verify issuer if (($payload['iss'] ?? '') !== "https://securetoken.google.com/$projectId") return null; // Verify audience if (($payload['aud'] ?? '') !== $projectId) return null; // Verify subject (firebase_uid) is present if (empty($payload['sub'])) return null; // Verify signature $kid = $header['kid'] ?? null; if (!$kid) return null; $keys = fetchFirebasePublicKeys(); if (!$keys || !isset($keys[$kid])) return null; $publicKeyPem = $keys[$kid]; $publicKey = openssl_get_publickey($publicKeyPem); if (!$publicKey) return null; $dataToVerify = "$headerB64.$payloadB64"; $verified = openssl_verify($dataToVerify, $signature, $publicKey, OPENSSL_ALGO_SHA256); openssl_free_key($publicKey); if (!$verified) return null; // Auth time check for phone auth (optional) $authTime = $payload['auth_time'] ?? 0; // If token is older than 24 hours, require re-auth if ($authTime > 0 && (time() - $authTime) > 86400) return null; return [ 'firebase_uid' => $payload['sub'], 'phone_number' => $payload['phone_number'] ?? null, 'email' => $payload['email'] ?? null, 'name' => $payload['name'] ?? null, ]; } function findUserByFirebaseUid(string $firebaseUid, mysqli $mysqli): ?array { $tables = [ 'teacher_profile' => 'Teacher_ID', 'manager_profile' => 'Manager_ID', 'master_profile' => 'Master_ID', 'admin_profile' => 'Admin_ID', ]; foreach ($tables as $table => $idCol) { $stmt = $mysqli->prepare("SELECT $idCol, User_Name, Password FROM $table WHERE firebase_uid = ? LIMIT 1"); if ($stmt) { $stmt->bind_param('s', $firebaseUid); $stmt->execute(); $stmt->store_result(); if ($stmt->num_rows === 1) { $stmt->bind_result($userId, $username, $password); $stmt->fetch(); $stmt->close(); return [ 'user_id' => $userId, 'username' => $username, 'password' => $password, 'table' => $table, 'id_col' => $idCol, ]; } $stmt->close(); } } return null; } function findUserByPhone(string $phone, mysqli $mysqli): ?array { $phone = preg_replace('/[^0-9]/', '', $phone); $tables = [ 'teacher_profile' => 'Teacher_ID', 'manager_profile' => 'Manager_ID', 'master_profile' => 'Master_ID', 'admin_profile' => 'Admin_ID', ]; foreach ($tables as $table => $idCol) { $stmt = $mysqli->prepare("SELECT $idCol, User_Name, Password, firebase_uid FROM $table WHERE Phone LIKE ? LIMIT 1"); if ($stmt) { $likePhone = '%' . $phone . '%'; $stmt->bind_param('s', $likePhone); $stmt->execute(); $stmt->store_result(); if ($stmt->num_rows === 1) { $stmt->bind_result($userId, $username, $password, $firebaseUid); $stmt->fetch(); $stmt->close(); return [ 'user_id' => $userId, 'username' => $username, 'password' => $password, 'firebase_uid' => $firebaseUid, 'table' => $table, 'id_col' => $idCol, ]; } $stmt->close(); } } return null; } function linkFirebaseUidToUser(string $firebaseUid, string $table, string $idCol, string $userId, mysqli $mysqli): bool { $stmt = $mysqli->prepare("UPDATE $table SET firebase_uid = ? WHERE $idCol = ?"); if ($stmt) { $stmt->bind_param('ss', $firebaseUid, $userId); $result = $stmt->execute(); $stmt->close(); return $result; } return false; }