KeyPad Password "Lock"

I'm currently developing a password protected "lock" (it really code be used to do anything). I've made it so that you can set a new password on the fly, without a computer. I'm fairly new to Arduino, with a limited background in programming, so any pointers would be appreciated!

The program work as expected, but I would like to add some more functionality in the near future.
Here's a list of feature I'd like to implement:
-Maximum code of 8 characters
-Ability to set more than one password
-Select a password slot (1-9) and set it
-If a password already exists in a slot, the user would be required to enter the previous password first or a Master password would have to be entered prior to setting a new one.

Like I said, I'm fairly new to Arduino so any improvements or comments would be great.

#include <Keypad.h>
#include <Password.h>

/*
To enter a code, punch in a four digit number and press '*'.  
If the password is correct an LED (or anything) will be turned on
for a certain amount of time.  To set a code, press on hold the '#'
key until an LED starts to flash, enter in a desired 4 digit code
and press '*' to set.  Press and hold '#' to exit programming mode.
At anytime when entering a code press '#' to clear the current entry.

- ThatRusty 2012
*/

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
// Define the keymap
char PadKeys[ROWS][COLS] = {
    { '1','2','3', 'D' },
    { '4','5','6' },
    { '7','8','9', 'S' },
    { '*','0','#', 'C' }
};


boolean setPass = false;   // Start with the entry keypad.

byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6,9}; //connect to the column pinouts of the keypad

// Create "two" new keypads, one is a entry pad and the other is a programming pad.
Keypad entryPad( makeKeymap(PadKeys), rowPins, colPins, sizeof(rowPins), sizeof(colPins) );
Keypad setPad( makeKeymap(PadKeys), rowPins, colPins, sizeof(rowPins), sizeof(colPins) );


unsigned long startTime;
const byte ledPin = 11;// Programming LED, flashes when in program mode
const byte ledPin1 = 13; //Green LED, correct code + key press
const byte ledPin2 = 12; //red LED, Error



Password password = Password( "5555" ); //Default password 1
Password password2 = Password( "4321" ); //Default password 2

char Password2[5]; //Array used to set password #2

char PasswordArray[5]; //General entry array, used to store key presses

int i = 0; //counter


void setup() {
    Serial.begin(9600);
    
    pinMode(ledPin, OUTPUT);
    pinMode (ledPin1, OUTPUT);
    pinMode(ledPin2,OUTPUT);
     
    digitalWrite(ledPin, LOW); // start programming LED off
    
    //Set up keypads    
    setPad.begin( makeKeymap(PadKeys) );
    entryPad.begin( makeKeymap(PadKeys) );
    setPad.addEventListener(keypadEvent_set);  // Add an event listener for programming mode
    setPad.setHoldTime(1000);                   // Set how long a key must be held before a hold key event
    entryPad.addEventListener(keypadEvent_entry);  // Add an event listener for entry mode
    entryPad.setHoldTime(1000);     // Set how long a key must be held before a hold key event
    entryPad.setDebounceTime(200);
    setPad.setDebounceTime(200);
}

char key; //Define key button variable

void loop() {

    if( setPass ) //if setpass == true, get key presses from the programming key pad
        key = setPad.getKey( );
    else
        key = entryPad.getKey( ); //if setpass == false, get key presses from the entry key pad

    if (setPass && millis()-startTime>100) {           // Flash the programming LED when in program mode
        digitalWrite(ledPin,!digitalRead(ledPin));
        startTime = millis();
        
    }
}


static byte kpadState; //Define variable to check key state (PRESSED, HOLD...)

// Take care of some special events.

void keypadEvent_set(KeypadEvent key) {
    // in here when in program mode.
    
    kpadState = setPad.getState( );
    swOnState( key ); //send swOnState function what key was pressed
} // end set keypad events

void keypadEvent_entry( KeypadEvent key ) {
    // in here when using the entry keypad
    
    kpadState = entryPad.getState( );
    swOnState( key );  //send swOnState function what key was pressed
} // end entry keypad events

void swOnState( char key ) {
    switch( kpadState ) {
        case PRESSED: //If a key was pressed
      blink(ledPin1, 50); //Blink LED when key is pressed, send which LED and how long of a delay
      
            if (setPass) {              // In program mode so we're using the programming keymap.
    
    switch (key){
     case '*':  setPassword(); //After you punch in you new password press '*' to set it
                break;
                 
     case '#': resetPasswordArray();  //Clear the Password array
               Serial.println("Clear");
               
             default:    
                          if (key != '#'){  //if the key pressed was not '#' , append key to entry array
                          PasswordArray[i] = key; i++;} //increment counter
                          if (key != '#') {Serial.print(key);} //Print out what key was pressed
    }
    

            }else{  //In entry mode, use entry keypad
            //Code Entry goes here
            
  
              switch(key){
              case '*': checkPassword();
                        break;
              case '#': resetPasswordArray();
                        Serial.println();
                        Serial.println("Clear");
              
              default:    
                          if (key != '#'){  //if the key pressed was not '#' , append key to entry array
                          PasswordArray[i] = key; i++;}   //increment counter
                          if (key != '#') {Serial.print(key);}  //Print out what key was pressed
                          
              }
           
                    
            }
                break;

        case HOLD:  
            if (key == '#')  {          //If '#' key was held toggle keypads     
                if (setPass == true)  {        // We are currently using a keymap with letters
                    setPass = false;           // Now we want a keymap with numbers.
                    digitalWrite(ledPin, LOW);
                }
                else  {                      //Currently using the entry keypad
                    setPass = true;            // Now we want to use the programming keypad
                }
                
            }
            
           break;

      
    }  // end switch-case
}// end switch on state function

void checkPassword() {
  Serial.println();
  
  if (i>3 && i<5){ //Only accept passwords that are 4 characters
    
  if (password.is(PasswordArray)){ //check punched in code againsted password
 
    Serial.println("Access Granted (1)");
    blink (ledPin1, 700); //Blink LED
  
    
   }else if (password2.is(PasswordArray)){  //If punched in code wasn't the first password check the second
   
    Serial.println("Access Granted (2)");
    blink (ledPin1, 700);
    
  } else {
      
     Serial.println("Access Denied");
     blink(ledPin2, 700);
    
  }
     
  }else{
 Serial.println("Your password must be 4 characters.");
blink(ledPin2, 700); 
  }   
      i=0; //reset counter so another code can be entered
    resetPasswordArray();
    password.reset();
    password2.reset();
  
} 

void setPassword(){
Serial.println();
if (i>3 && i<5) { //Only accept passwords that are 4 characters
for (i=0;i<4;i++){
  Password2[i] = PasswordArray[i];  //Set Password2 array to characters in entry array
}
password2.set(Password2); //Set password2 to the punched in code
Serial.println("New password has been set...");
}else{
 Serial.println("Your password must be 4 characters.");
blink(ledPin, 700); 
}
i=0; //reset counter
resetPasswordArray();
// User must exit program mode by holding the '#' key

}

void resetPasswordArray() { //Clear entry array
  
       for (i=0;i<5;i++){
    PasswordArray[i] = '\0'; //set all characters in the entry array to null
    }
     
    i=0; //reset counter
}

void blink (const byte LED, int DELAY){
  
  digitalWrite(LED, !digitalRead(LED));
  delay (DELAY);
  digitalWrite(LED, !digitalRead(LED));
  
}
// Create "two" new keypads, one is a entry pad and the other is a programming pad.
Keypad entryPad( makeKeymap(PadKeys), rowPins, colPins, sizeof(rowPins), sizeof(colPins) );
Keypad setPad( makeKeymap(PadKeys), rowPins, colPins, sizeof(rowPins), sizeof(colPins) );

But, you only have one piece of hardware. Why are there two instances that refer to the same hardware?

const byte ledPin = 11;// Programming LED, flashes when in program mode
const byte ledPin1 = 13; //Green LED, correct code + key press
const byte ledPin2 = 12; //red LED, Error

Three LEDs - nothing, 1, and 2. I don't get it.

Password password = Password( "5555" ); //Default password 1
Password password2 = Password( "4321" ); //Default password 2

Two passwords - nothing and 2. I don't get it.

char Password2[5]; //Array used to set password #2

Variable names that differ only in case are a really bad idea.

    setPad.addEventListener(keypadEvent_set);  // Add an event listener for programming mode
    entryPad.addEventListener(keypadEvent_entry);  // Add an event listener for entry mode

When a key is pressed on the hardware, which callback do you want called?

My reasoning behind creating "two" keypad was so I could have two different Keypad Listeners. I was having issues before that when I went into program mode my keypad would do the code that was in my entry mode. Looking at it now, and with the little bit of experience I now have, this could probably be done with one keypad listener.

// Create "two" new keypads, one is a entry pad and the other is a programming pad.

Keypad entryPad( makeKeymap(PadKeys), rowPins, colPins, sizeof(rowPins), sizeof(colPins) );
Keypad setPad( makeKeymap(PadKeys), rowPins, colPins, sizeof(rowPins), sizeof(colPins) );



But, you only have one piece of hardware. Why are there two instances that refer to the same hardware?

The LEDs are just named whatever, I guess they could be BlueLED, GreenLED and RedLED. I had just started coding and then as I got more into it, I added more and more LEDs.

Three LEDs - nothing, 1, and 2. I don't get it.

Same with the passwords as the LEDs.

Two passwords - nothing and 2. I don't get it.

These technically are not the same thing; Password2 is an Array and password2 is a password. If I were to have gone: char password2[5]; I would have got an error since password2 has already been defined as a password.

Variable names that differ only in case are a really bad idea.

I was having issues before that when I went into program mode my keypad would do the code that was in my entry mode. Looking at it now, and with the little bit of experience I now have, this could probably be done with one keypad listener.

Could, and should. The program knows whether it is in program mode or entry mode. The listener should (have), too.

The LEDs are just named whatever, I guess they could be BlueLED, GreenLED and RedLED.

Or ledPin1, ledPin2, and ledPin3. My point was that if you are going to number the second and subsequent instances, you should number the first one, too.

These technically are not the same thing; Password2 is an Array and password2 is a password.

But password and password2 are both instance of the Password class. I expect to see them both numbered or named in such a way that they don't need to be numbered.

If I were to have gone: char password2[5]; I would have got an error since password2 has already been defined as a password.

However, if you'd named the char array variable pass2AsArray, there would have been no such problem, and later in the code, password2 and pass2AsArray are clearly different things.

Hey, I am trying to do the same thing with my keypad i.e try and reset the current password on it and I am just wondering whether you have a final code that eventually worked for you?
Thanks