Aroo
Aroo

Reputation: 141

Google Sheets multiple passwords

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?

Upvotes: 0

Views: 131

Answers (1)

idfurw
idfurw

Reputation: 5862

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

Reference:

Array.prototype.includes()

Upvotes: 2

Related Questions