#include <EEPROM.h>

String passKey = "EEE20003";
int length = passKey.length() + 100;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  int j = 0;
  
  // Putting passKey into EEPROM at specific address
  for (int i = 100; i < length; i++) { // For loop for length of passKey
    EEPROM[i] = passKey.charAt(j); // Insert each individual character
    j++;
  }

  Serial.println();
}

void loop() {
  // put your main code here, to run repeatedly:
  keyEntry();
  
  Serial.println();
}

// Function to compare input to saved EEPROM
void keyEntry() {
  bool result = false;

  while(Serial.available() == 0) {} // freeze program until input is given
  String attempt = Serial.readStringUntil('\n');

  // for loop to compare input with EEPROM
  int j = 0;
  for (int i = 100; i < (length); i++) {
    char check = EEPROM.read(i);
    if (check == attempt[j]) {
      result = true;
    } else {
      result = false;
    }
    j++;
  }

  // Make sure length of input is correct
  if (attempt.length() != 8) {
    result = false;
  }

  // saying whether or not correct password was entered
  if (result == true) {
    Serial.println("Granted");
  } else {
    Serial.println("Denied");
  }
}