title: Need to check for login username and password, and then bring data from previous entries
body: <p>Following this question I had asked previously (<a href="https://stackoverflow.com/questions/65717284/need-to-query-google-sheet-for-specific-data-from-google-apps-script">Need to Query Google Sheet for specific data from Google Apps Script</a>).</p>
  <p>I have created a web app to track the working hours of employees at my company, the web app is simple, it first asks them to provide their username and a password, and then allows them to register their time of entry o their exit time. Now, I need to find a way to check for a match between username and password (in a data base), and if this is true, bring information about that employee's last submission to the web app, this last submission data is found on another sheet that receives the data from the web app.</p>
  <p>Here is a minimal reproducible example, where its just asks for a name and a password, and if correct, show another display, where it brings the timestamp of that user's last submission to the web app.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var name="";
  
  function doGet(e) {
    return HtmlService.createHtmlOutputFromFile('Form');
  }
  function AddRecord(Name) {
    
    // get spreadsheet details
    var url = 'https://docs.google.com/spreadsheets/d/1CJoPuq3sHE5L31GwlvS4Zygm1sL3M0HGC7MgW3rCq3g/edit#gid=0';
    //Paste URL of GOOGLE SHEET
    var ss1= SpreadsheetApp.openByUrl(url);
    var webAppSheet1 = ss1.getActiveSheet();
    const Lrow = webAppSheet1.getLastRow();
    const data = [Name, new Date ()];
  
    webAppSheet1.getRange(Lrow+1,1, 1, data.length).setValues([data])       
  }
  
  function checklogin(Name,Password) {
    var url = 'https://docs.google.com/spreadsheets/d/1CJoPuq3sHE5L31GwlvS4Zygm1sL3M0HGC7MgW3rCq3g/edit#gid=0'; //Paste URL of GOOGLE SHEET
    var ss2= SpreadsheetApp.openByUrl(url);
    var webAppSheet2 = ss2.getSheetByName("DataBase");
    var checkuser = webAppSheet2.getRange(2, 1, webAppSheet2.getLastRow(), 1).createTextFinder(Name).matchEntireCell(true).findNext();
    var obj = {checkuser: checkuser ? 'TRUE' : 'FALSE'};
    var sheet = ss2.getSheetByName("ReceivedData");
    var ranges = sheet.getRange(2, 1, sheet.getLastRow(), 1).createTextFinder(Name).matchEntireCell(true).findAll();
    if (ranges.length &gt; 0) {
      obj.lastTimestamp = ranges.pop().offset(0, 1, 1, 1).getDisplayValue();
      return obj;
    }
    return obj;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;base target="_top"&gt;
      &lt;style&gt;
      #LastR{
      display: inline-block;
      }
      &lt;/style&gt;
      &lt;script&gt;
      function AddRow()
      {
        var Name = document.getElementById("Name").value;  
        google.script.run.AddRecord(Name);
        document.getElementById("Name").value = '';
        }    
  function LoginUser() {
    var Name = document.getElementById("Name").value;
    var Password = document.getElementById("Password").value;
    google.script.run.withSuccessHandler(function({checkuser, lastTimestamp}) {
      if(checkuser == 'TRUE') {
        document.getElementById("loginDisplay").style.display = "none";
        document.getElementById("dataDisplay").style.display = "block";
        document.getElementById("lastTimestamp").innerHTML = lastTimestamp;
      } else if(checkuser == 'FALSE') {
        document.getElementById("errorMessage").innerHTML = "Name not found";
      }
    }).checklogin(Name,Password);
  }
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div id="loginDisplay"&gt;
      &lt;div&gt; 
      &lt;label&gt;Name&lt;/label&gt;&lt;br&gt;
      &lt;input type="text" id="Name" /&gt;
      &lt;/div&gt;
          &lt;div&gt; 
      &lt;label&gt;Password&lt;/label&gt;&lt;br&gt;
      &lt;input type="text" id="Password" /&gt;
      &lt;/div&gt;
      &lt;div class="btn"&gt;
  &lt;input value="Login" onclick="LoginUser()"
   type="button"&gt;
   &lt;span id="errorMessage"&gt;&lt;/span&gt;
  &lt;/div&gt; 
  
      &lt;/div&gt;
      &lt;div style="display:none"  id="dataDisplay"&gt;
      &lt;div&gt;
  &lt;label&gt;Last Registration&lt;/label&gt;
  &lt;br&gt;&lt;br&gt;
  &lt;div class="LastR" id="lastTimestamp"&gt;&lt;/div&gt;
  &lt;button type="button" value="Add" onclick="AddRow()"&gt;Send&lt;/button&gt;
  &lt;/div&gt;
  &lt;/div&gt;
    &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>And here is a sheet where you can work from or copy the information.
  <a href="https://docs.google.com/spreadsheets/d/1CJoPuq3sHE5L31GwlvS4Zygm1sL3M0HGC7MgW3rCq3g/edit#gid=0" rel="nofollow noreferrer">https://docs.google.com/spreadsheets/d/1CJoPuq3sHE5L31GwlvS4Zygm1sL3M0HGC7MgW3rCq3g/edit#gid=0</a></p>