lcd keypad

How do i stop the password from "sliding"
if the password is 123456 and i enter 1234567 the password is still valid?

You really need to make some changes to the code. The password to check against should be a string, not an array of chars. Change

char PIN[6]={
  '1','2','3','4','5','6'}; // our secret (!) number

to

char PIN[] = "123456";

Then, in the readKeypad() function,

    default:
      attempt[z]=key;
      z++;
      attempt[z] = '\0';

The new line changes attempt from a char array to a string.

Finally, in checkPIN():

  int correct=0;
  for (int q=0; q<6; q++) 
  {
    if (attempt[q]==PIN[q])
    {
      correct++;
    }
  }

becomes

   int correct = strcmp(attempt, PIN);

You'll need to make some other changes, because correct will now be -1, 0, or +1. 0 means that the attempt and PIN strings are the same. +1 or -1 mean that they are not.