Two identical strings do not enter the bet

Hi friends, I need help, please help.
I read a password from a text file and put it in a string to be the main password.
Then I want to enter the password from the input of the monitor serial.
But when I compare them, even though the strings are the same. Does not enter the condition.
How do I make an equal condition?

Code:

#include <SD.h>
File M_Pass;
String Password_From_SD="";
void setup() {
  Serial.begin(115200);
  SD.begin(10);
  Get_str_From_SD();
}
void loop() {
   Menu();
}
void Menu(){
  String Enter_Password_Serial="";
  Serial.println("Enter Password:");
  while (!Serial.available());
  Enter_Password_Serial = Serial.readString();
  Serial.print("Enter_Password_Serial:");
  Serial.println(Enter_Password_Serial);
  Serial.print("Password_From_SD:");
  Serial.println(Password_From_SD);
  if(Enter_Password_Serial==Password_From_SD){
    int buttom_menu=0;
    Serial.println("request number:");
    Serial.println("1.Something");
    Serial.println("2.Something");
  }
  else{
    Serial.println("Password incorrect");
  }
}
void Get_str_From_SD(){
  M_Pass=SD.open("PM.txt");
  char character;
  while (M_Pass.available())
  {
    character = M_Pass.read();
    Password_From_SD += character;
  }
}

I heard strings have "end of string" symbol at the end of string.
Inputs from Serial Monitor window have "New Line" and "Carriage Return" symbols at the end.

1 Like

In the wokwi, to which you could have "shared" a link BTW, check the documentation for the serial monitor, where you can change the line ending, just like you might in the serial monitor window in the IDE.

a7

2 Likes

Thank you very much, I fixed it with your help by setting the monitor serial in the IDE on (No line ending). :heart: :rose:

Thank you very much, I fixed it by your help. :heart: :rose:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.