keypad blocking function for a specific time

I am using a keypad 4x4 and I want to read a PIN from this, but I want the blocking function to wait for a certain amount of time. The waitForKey() that I use, blocks the whole code. Here is my function.

void set_password()
{
    pass[0] = myKeypad.waitForKey(); 
    pass[1] = myKeypad.waitForKey(); 
    pass[2] = myKeypad.waitForKey(); 
    pass[3] = myKeypad.waitForKey(); 
}

don't block, just call the waitForKey() function and fill an array...

index the array after each entry test it after you recieve four. Restart on a timeout if some n seconds transpire and the entry is not complete.

What you describe sounds like a timeout on user input. If so, use getKey() and a millis() based timing. If a key was pressed, reset the start time of the timeout to the current time. If the result of getKey() equals NO_KEY, check the start time of the timeout against the current time and if it exceeds a limit, do whatever needs to be done on timeout