About adding a new functionality to the code.

void checkpassword()
{
  int d = 0;
  int e;
  int y = 0;

  Serial.println(" Enter your PassKey: ");

  while(d<4)
  {
    key = kpd.getKey();
  if(key != NO_KEY)
  {
    pass3[d] = key;
    Serial.println("*");
    d++;
  }}

  while(y<4)
  {
    char test3 = pass3[y];
    char test4 = pass2[y];
    if(test3 != test4)
    {
      result1 = false;
    }
    else
    {
      result1 = true;
    }
    y++;
  }

  if(result1 == true)
  {
    Serial.println("Entered pass key is correct");
  }
  else
  {
    Serial.println("Wrong Password, Try again");
    delay(30000);
    call2();
  }
}

In this code, I want to add this feature: If the password is entered wrong 3 times, then it must again go to another function where in some authentication has to be performed. What extra lines should i add to this code to make it work the way i want ?

Thanks in advance.

You will need a variable to keep track of the number of times it was incorrectly entered. In the last part where you notify the user that the password is wrong, add one to that variable. Then test that variable with an if statement. If it is 3 or greater, call whatever function you want to call.

What extra lines should i add to this code to make it work the way i want ?

First, you need to fix the crap you have.

ONE close curly brace per line. NEVER more than one.

Use Tools + Auto Format!

Use variable names that make sense. d, e, and y do not.

You need some static or global variable to count the number of times that the user has tried to break into your system.

When the number of attempts exceeds your threshold, do something.

   call2();

Another meaningless name. How would you like to have to get out a manual to look up the Arduino functions? You don't need to because the names make sense. You can reasonably guess what digitalWrite() will do. There isn't a hope in hell that anyone can guess what call2() does.

Some comments:

The way you made it now makes the code blocking. It keeps waiting until you entered the whole password.

Also, it’s not the whole code! You should post at least complable code.

And I see a lot of variables that aren’t declared inside the function so must be global. But I see no need for pass3 (which is a terrible terrible variable name) and others to be global.

And the function is called checkpassword (checkPassword would be preferred) but it does more then that. I would split it between a enter password, a check password function and a update password function. NOTE, I made a blocking version as well because you didn’t post all the code. Also, how do you recall the checkpassword() function now?

void updatePassword()
{
  static byte attempts = 0;
  char typedPassword[PasswordLength];
  
  inputPassword(typedPassword);
  
  if(checkPassword(typedPassword))
  {
    Serial.println("Entered pass key is correct");
    attempts = 0;
  }
  else
  {
    Serial.println("Wrong Password, Try again");
    attempts++;
    if(attempts >= MaxAttempts)
    {
      //Do something about it!
    }
    delay(30000);
    //call2(); //to where?
  }
}

void inputPassword(char password[])
{
  int d = 0;
  //int e; //not used

  Serial.println(" Enter your PassKey: ");

  while(d<4)
  {
    char key = kpd.getKey(); //no need for global
    if(key != NO_KEY)
    {
      password[d] = key;
      Serial.println("*");
      d++;
  }} //See the double bracket? That means you f*ck up the indentation ;)
}

bool checkPassword(char password[])
{
  for(byte i = 0; i < PasswordLength; i++) //think a for look is more clear
  {
    //char test3 = pass3[y]; no need for this
    //char test4 = pass2[y];
    if(password[i] != setPassword[i])
    {
      return false;
    }
   
    //y++; don by the for-loop
  }
  
  return true; //if non triggered a return befor the password is correct
}