Help with password code

hey guys, I am a little new to Arduino and I was wondering if I could get some help on one of the projects I am working on right now.

So what happens is that I have a string called "key" that has a password stored on it beforehand such as "banana" when I type into my serial monitor it will send what I typed to the LCD and if what I typed and what the password is are the same then there is a message on the LCD saying "Correct password". But if it not the correct password then there is a try again message. What I am having trouble with is getting the Serial.read() to be compared to my "key" variable in my if statements. I would really be grateful if someone would help out, my code is below.

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
#include <LiquidCrystal.h>
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
String key = "radical dude";

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // initialize the serial communications:
  Serial.begin(9600);
  
}

void loop() {
  // when characters arrive over the serial port...
  if (Serial.available()) {
    // wait a bit for the entire message to arrive
    delay(100);
    // clear the screen
    lcd.clear();
    // read all the available characters
    while (Serial.available() > 0) {
      // display each character to the LCD
      lcd.write(Serial.read());
    }
  }
  if (Serial.read == key){
    lcd.clear();
    lcd.print("Password accepted");
  }
  if (Serial.read != key){
    lcd.clear();
    lcd.print("Incorrect");
  }
  
}

In the if statements it keeps saying that I have a "non-static member function".

Second guessing what happens in an asynchronous line with synchronous code is calling for trouble...

  if (Serial.available()) {
    // wait a bit for the entire message to arrive
    delay(100);

Read Serial Input Basics And get familiar with those C functions in stdlib.h and string.h and drop usage of the String class

      lcd.write(Serial.read());
    }
  }
  if (Serial.read == key){
    lcd.clear();
    lcd.print("Password accepted");
  }

Where are the brackets in the function call ?
BUT, even with that fixed will reading a single byte that has already been removed from the buffer 3 lines above ever equal a string of multiple characters ?

Nevermind I solved it,

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
#include <LiquidCrystal.h>
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const int key = 97;
int password = 0;


void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // initialize the serial communications:
  Serial.begin(9600);
  lcd.print("Enter the ");
  lcd.setCursor(0,1);
  lcd.print("password");
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  
}

void loop() {
  // when characters arrive over the serial port...
  if (Serial.available()) {
    // wait a bit for the entire message to arrive
    delay(100);
    // clear the screen
    lcd.clear();
    // read all the available characters
    while (Serial.available() > 0) {
      // display each character to the LCD
      int password = Serial.read();
      Serial.println(Serial.read());
      if (password == key){
        lcd.clear();
        lcd.print("Acsess Granted");
        digitalWrite(10, HIGH);
        delay(1000);
      }
      if (password != key){
        lcd.clear();
        lcd.print("Incorrect,please");
        lcd.setCursor(0,1);
        lcd.print("try again");
        digitalWrite(9, HIGH);
        delay(100);
        digitalWrite(9, LOW);
        delay(100);
        digitalWrite(9, HIGH);
        delay(10000);
      }
    }
   }

  
  
}

:slight_smile: :slight_smile: :slight_smile:

const int key = 97;
      if (password == key)

A single letter password ?

Super secure :slight_smile: