Home > Back-end >  Google Sheets multiple passwords
Google Sheets multiple passwords

Time:11-19

I have the following appscript in my google sheets which asks user to input the password to access the file.

function openSheets(){
  SpreadsheetApp.getActive().getActiveSheet().hideRows(3, 31);
  hideAllSheetsExcept('Sheet1')
}

function hideAllSheetsExcept(sheetName) {

  var sheets=SpreadsheetApp.getActiveSpreadsheet().getSheets();
  for(var i =0;i<sheets.length;i  ){
    Logger.log(i);
    if(sheets[i].getName()!=sheetName){
      sheets[i].hideSheet();
    }
  }
  var quest="";
  while (quest!='123'){
    quest = Browser.inputBox("Enter password");
  }
  SpreadsheetApp.getActive().getActiveSheet().showRows(3, 31);
  SpreadsheetApp.getActive().getRange('B5').activate();
}

I want to share this with my friends like 3 of them. But I want to give them each a different password to access this. How can I change this code to accept multiple passwords?

CodePudding user response:

  const pw = ['123', '456', '789'];
  while (!pw.includes(quest)){
    quest = Browser.inputBox("Enter password");
  }

Reference:

Array.prototype.includes()

  • Related