how to control led with password

hello i have question about making password to control led

i have control led high and low with one key based on the code below

#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 

void setup(){
  Serial.begin(9600);
}
  
void loop(){
  char customKey = customKeypad.getKey();
  
  if (customKey){
    Serial.println(customKey);
  }
  if (customKey=='1'){
    digitalWrite(12,HIGH);
     
  }
  if (customKey=='2'){
    digitalWrite(12,LOW);
     
  }
}

the problem, how to make password to control high and low for example : i preesed “1234” and “#” and led high
then i pressed “4321” and “#” the led become low

thanks for the helping … sorry my bad english

hello i have question about making password to control led

There is a password class for the Arduino. It even has examples that use a keypad to enter the password. Seems right up your alley.

Here is an easy way:

void loop(){
  static char Key1 = 0, Key2 = 0, Key3 = 0, Key4 = 0;
  char customKey = customKeypad.getKey();
  
  if (customKey == '#') {
    if (Key1 == '1' && Key2 == '2' && Key3 == '3' && Key4 == '4')
      digitalWrite(12,HIGH);
    if (Key1 == '4' && Key2 == '3' && Key3 == '2' && Key4 == '1')
      digitalWrite(12,LOW);
  }
  else {
    Key1 = Key2;
    Key2 = Key3;
    Key3 = Key4;
    Key4 = customKey;
  }
}