Door lock problem

Hello, In my project we have a servo motor that is supposed to open a door, We want to have a phone app(Using firebase) to be able to control the door for example.
We are using Arduino Mega, NodeMCU ESP8266, servo motor,Keypad and an alarm
The problem: We have an option to close/open the servo motor using the Firebase, but when you enter the right password in keypad, the door opens and closes shortly after, we believe its because the firebase sends arduino to close the door. Any ideas how to fix it?
Thanks in advance
Arduino Code:

#include <Keypad.h>
#include <LiquidCrystal.h>
#include <Servo.h>
#include <Wire.h>
Servo myservo;
LiquidCrystal lcd(49,48,47,46,45,44);
#define Password_Lenght 6 // Give enough room for six chars + NULL char
int pos = 0;    // variable to store the servo position
int count = 0;
int buzzerPin = 40;
char Data[Password_Lenght]; // 6 is the number of chars it can hold + the null char = 7
char Master[Password_Lenght] = "*1234";
byte data_count = 0, master_count = 0;
bool Pass_is_good;
char customKey;
String allSensorsData;
String A = "ABCD";
String B = "BDA";
int j;
char str[50];
String data1 = "";
String data2 = "";
int length1,length2 = 0;
int g = 0;
const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};
bool door = true;

byte rowPins[ROWS] = {8, 7, 6, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4, 3, 2}; //connect to the column pinouts of the keypad

Keypad customKeypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS); //initialize an instance of class NewKeypad

void setup()
{
  Wire.begin(8);
  Wire.onReceive(receiveEvent);
  Wire.onRequest(requestEvent);
  Serial.begin(9600);
  pinMode (buzzerPin, OUTPUT);
  myservo.attach(9);
  ServoClose();
  lcd.begin(16,2);
  lcd.print("      Vault");
  lcd.setCursor(0,1);
  lcd.print(" Maor and Shay");
  delay(2250);
  lcd.clear();
}

void loop()
{
  CheckPassword();
  SensorsData();
// requestEvent();
 //receiveEvent();
 PasswordChange();
 DoorStatus();
 Serial.println(data1);
 Serial.println(data2);
 ClearStrings();
}
void CheckPassword()
{
   if (door == 0)
  {
    customKey = customKeypad.getKey();

    if (customKey == '#')

    {
      lcd.clear();
      ServoClose();
      lcd.print("Door is closed    ");
      delay(3000);
      door = 1;
      lcd.clear();
    }
  }

  else Open();
}
void clearData()
{
  while (data_count != 0)
  { // This can be used for any array size,
    Data[data_count--] = 0; //clear array for new data
  }
  return;
}

void ServoOpen()
{
    myservo.write(90);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
}

void ServoClose()
{
    myservo.write(0);              // tell servo to go to position in variable 'pos'
    delay(30);                       // waits 15ms for the servo to reach the position
}

void Open()
{
lcd.setCursor(0, 0);
 if(count==0) lcd.print("Enter Vault");
 else lcd.print("Try again");
  customKey = customKeypad.getKey();
  if (customKey) // makes sure a key is actually pressed, equal to (customKey != NO_KEY)
  {
    Data[data_count] = customKey; // store char into data array
    lcd.setCursor(data_count, 1); // move cursor to show each new char
    lcd.print('*'); // print char at said cursor
    data_count++; // increment data array by 1 to store new char, also keep track of the number of chars entered
  }

  if (data_count == Password_Lenght - 1) // if the array index is equal to the number of expected chars, compare data to master
  {
    if (!strcmp(Data, Master)) // equal to (strcmp(Data, Master) == 0)
    {
      lcd.clear();
      if(count <3){
      ServoOpen();
      lcd.print("Door is Open");
      door = 0;
      }
      else{
      lcd.print("Alarm OFF");
      }
      delay(1250);
      count = 0;
    }
    else
    {
      count++;
      lcd.clear();
      lcd.print("Wrong Password");
      delay(1000);
      door = 1;
      lcd.clear();
    }
    clearData();
    AlarmPassword();
  }
}
void AlarmPassword()
{
if(count > 2)
    {
     // Serial.println("Alarm ON");
      digitalWrite (buzzerPin, HIGH);
    }
    else if(count ==0) {
   // Serial.println("Alarm OFF");
   digitalWrite(buzzerPin,LOW);
        count = 0;}
}

void receiveEvent() {
  j = 0;
 while (Wire.available()) {
    char c = Wire.read();      /* receive byte as a character */
    str[j] = c;
    j++;
  }
 //Serial.println(str);             /* to newline */
}
int i;
void requestEvent() {
  for(i = 0;i<15;i++){
 Wire.write(allSensorsData[i]);  /*send string on request */
  }
  delay(500);
}
String SensorsData(){
  allSensorsData += A+","+B+",";
  return allSensorsData;
}
void ClearStrings(){
   data1 = "";
   data2 = "";
}
String PasswordChange(){
  g = 0;
  while(str[g]!=',')
  {
    Master[g]=str[g];
    data1+=Master[g];
    g++;
  }
  length1 = g;
  return data1;
}
String DoorStatus(){
  g = length1+1;
  while(str[g]!=',')
  {
    data2+=str[g];
    g++;
  }
  length2=g;
  if(data2 == "Open") ServoOpen();
  else ServoClose();
  return data2;
}

NodeMCU Code:

#include <Firebase.h>
#include <FirebaseArduino.h>
#include "FirebaseArduino.h"
#include <ESP8266WiFi.h>
#include<ArduinoJson.h>
#include <FirebaseArduino.h>
#include <Wire.h>
#define FIREBASE_HOST "Censored  
#define FIREBASE_AUTH "Censored" 
#define WIFI_SSID "Censored" 
#define WIFI_PASSWORD "Censored" 
String allSensorsData = "";
String Pass,DoorStatus;
char s[15];
int i,j,length1;
int g = 0;
String data1 = "";
void setup() { 
  Serial.begin(9600); 
  Wire.begin(D1, D2);
  // connect to wifi. 
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD); 
  Serial.print("connecting"); 
  while (WiFi.status() != WL_CONNECTED) { 
    Serial.print("."); 
    delay(500); 
  } 
  Serial.println(); 
  Serial.print("connected: "); 
  Serial.println(WiFi.localIP()); 
   
  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); 
} 

void loop() {
  GetDataFromFirebase();
  SensorsData();
  SendDataToSlave();
  GetDataFromSlave();
  MovementSensor();
  ClearStrings();
}
void GetDataFromFirebase(){
  Pass = Firebase.getString("Password");
  DoorStatus = Firebase.getString("Door");
}
void SendDataToSlave(){
  Wire.beginTransmission(8); /* begin with device address 8 */
 for(j = 0;j<15;j++){
 Wire.write(allSensorsData[j]);  /* sends hello string */
 }
 delay(500);
 Wire.endTransmission();    /* stop transmitting */
}
 void GetDataFromSlave(){
  Wire.requestFrom(8, 13);
  i = 0;
 while(Wire.available()){
    char c = Wire.read();
  //Serial.print(c);
  s[i] = c;
  i++;
 }
 }
 void ClearStrings(){
  allSensorsData = "";
  data1 = "";
 }
String SensorsData(){
  allSensorsData+=Pass+","+DoorStatus+",";
  return allSensorsData;
}
String MovementSensor(){
  g = 0;
  while(s[g]!=',')
  {
    data1+=s[g];
    g++;
  }
  length1 = g;
  Serial.print(data1);
  Serial.print("-");
  Serial.print(length1);
  Serial.println();
  return data1;
}

In short : There are 2 ways to open/close the door, the way through Firebase works good, but when we enter the right password in keypad and the door opens, it closes shortly after(We want it to close after pressing '#' - Works without the firebase).

See how to use password with keypad

IoT_hobbyist:
See how to use password with keypad

the keypad works fine, I need a suggestion how to fix the problem with the firebase and servo

This function

String SensorsData() {
  allSensorsData += A + "," + B + ",";
  return allSensorsData;
}

causes allSensorsData to grow and grow and grow since you never reset it to the empty string. That may be part of your problem.