How to compare two integer passwords using array

I should use a switch statement for that?

No.

if (key >= '0' && key <='9')
 Should I use a delay?

No
If no key is entered go round again, either the loop() function or a local while loop, until you get a valid input. Process it, add to the digit count and when 4 have been entered and added to the target set a boolean variable to flag data entry is complete. When the flag is true, and only then, compare the user input with the password.