How to set multiple values for a passcode on keypad

I'm using an arduino uno and a 3x4 keypad. My question is how can I input multiple keypresses so that it creates passcode to turn on an led. Example I want my passcode to be "1234", and inputing this passcode turns on the led.

The code I'm using now works so that I can press one digit and it will turn on the led.

#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
byte rowPins[ROWS] = {8, 7, 6, A0}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {13, 10, 9}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
int led=A1;


void setup(){
  Serial.begin(9600);
pinMode(led, OUTPUT);
 
}
  
void loop(){
  char key = keypad.getKey();
  digitalRead(key);
  switch(key){
    case '1':
    digitalWrite(led,HIGH);
    delay(5000);
    break;
    default:
    digitalWrite(led,LOW);
      
  }
   
  if (key){
    Serial.println(key);
  }
}

There are a number of ways to do what you describe. Here are two of them

Method 1
Initialise a target variable to zero
Read a character from the keypad when it becomes available
If the character is between '0' and '9' subtract '0' from it
Multiply the target by 10 and add the number from the step above
Do that 4 times and you have a 4 digit number in the target variable

Method 2
Declare a char array of 5 characters
Declare an index variable and initialise it to zero
Read a character from the keypad when it becomes available
If the character is between '0' and '9' save it to the array at the current index position, increment the index and put '0' in the array at that position to terminate the string
Do that 4 times and save 4 characters and you have a C string containing 4 characters
Use the atoi() function to convert the string to an int