Some pseudocode:
passwordCorrect = false;
attemptCount = 0;
while ((attemptCount < 3) & (passwordCorrect == false))
{
pwd = getPassword
attemptCount++
passwordCorrect = isPasswordCorrect(pwd)
}
if passwordCorrect != true
{
displayErrorMessage
QuitOrExitOrWhateverElseHere
}