Need help with making a password circuit + writing code

Now that you got it working, you can start making it more efficient.

If you want, you can make this part

key1State = digitalRead(key1);
if (key1State == HIGH) {
password.append('1');
Serial.println("1");
}
key2State = digitalRead(key2);
if (key2State == HIGH) {
password.append('2');
Serial.println("2");
}
key3State = digitalRead(key3);
if (key3State == HIGH) {
password.append('3');
Serial.println("3");
}
key4State = digitalRead(key4);
if (key4State == HIGH) {
password.append('4');
Serial.println("4");
}

into a FOR loop. If the button is high, return the index.
Now this would mean you would need to reverse these,

const int key1 = 7;
const int key2 = 6;
const int key3 = 5;
const int key4 = 4;

so that all you would need to do is subtract 3 from the index to get what button was pressed.