`;
// HTML content for the login page var loginPage = `



document.getElementById("loginForm").addEventListener("submit", function(event) { event.preventDefault(); // Prevent form submission var username = document.getElementById("username").value; var password = document.getElementById("password").value; google.script.run.withSuccessHandler(handleLoginResponse).login(username, password); }); function handleLoginResponse(response) { if (response === true) { document.getElementById("message").innerHTML = "Login successful!"; // Open the Google Form in a new tab or window window.open("https://docs.google.com/forms/d/e/1FAIpQLSeOlCNEO_x0KKckhy0kXC5YBGp-hatoEyaQFEKobtKVecRuKw/viewform"); } else { document.getElementById("message").innerHTML = "Invalid username or password."; } } `; // Function to handle login attempts function login(username, password) { var spreadsheetId = "18LfvCWF15r2Z80PAjm0pR413ZlAJYlo3OGZRuLrfD48"; var sheetName = "Sheet1"; var range = sheetName + "!A:B"; var sheetData = SpreadsheetApp.openById(spreadsheetId).getSheetByName(sheetName).getRange(range).getValues(); for (var i = 1; i < sheetData.length; i++) { var storedUsername = sheetData[i][0]; var storedPassword = sheetData[i][1]; Logger.log("Stored Username: " + storedUsername); Logger.log("Stored Password: " + storedPassword); if (username === storedUsername && String(password) === String(storedPassword)) { return true; // Valid credentials } } return false; // Invalid credentials } // Function to handle HTTP GET requests function doGet() { return HtmlService.createHtmlOutput(loginPage); }