How can I Compare data saved in SD card csv file with Keypad input?

I am trying to develop a logging system.I have a CSV file which contains usernames and Passwords.. by entering 4 numbers password it supposed to compare it with the passwords saved in the file. If it matches any, it will print “ Welcome -Username-”.. the code also is required to read data from altitude sensor when there is no obstacle in front of IR sensor and then save altitude sensor data into a new file. after it successfully matched a password it will print the sensor readings .. how can i do the password comparison part ??

#include <Keypad.h>
#include <Password.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
#include <SD.h> 
#include <SPI.h> 

File mySensorData;
File Trials ;
File NamePass;

Adafruit_BMP280 bme;
float Temperature , Pressure , Altitude ;
String newPasswordString; //hold the new password
char   newPassword[4]; //charater string of newPasswordString
int chipSelect = 10; 

//initialize password to 1234
//you can use password.set(newPassword) to overwrite it

Password password = Password( "1234");
byte maxPasswordLength = 4; 
byte currentPasswordLength = 0;

const byte ROWS = 4; // Four rows
const byte COLS = 4; // Four columns
//Define the keymap
char keys[ROWS][COLS] = {
//// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = {6,7,8,9}; //connect to row pinouts
// Connect keypad COL0, COL1, COL2 and COL3 to these Arduino pins.
byte colPins[COLS] = {5,4,3,2}; //connect to column pinouts
// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup()
  Serial.println(F("BMP280 test"));
  Wire.begin ();
  if (!bme.begin())
    Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
    while (1);

 void loop()
  char user , Name ,key ;
  user = (key + "," +  Name) ;

  user = ("NamePass.csv" ,FILE_READ ) ;
    key = keypad.getKey();
    if (key != NO_KEY)
         Trials ="trials.csv", FILE_WRITE);
         Trials.print(key ,password.evaluate());
          if (currentPasswordLength == maxPasswordLength) 
                 if (password.evaluate())
                     Serial.println(" OK.");
                     mySensorData ="Data.csv", FILE_WRITE);
                     Temperature  = bme.readTemperature();
                      Pressure    = bme.readPressure   ();
                      Altitude    = bme.readAltitude   ();
                          Serial.print( "Temperature = \t " );
                          Serial.print( "\t Pressure = \t " );
                          Serial.print( "\t Altitude = \t " );
                          mySensorData.print( " \t " );
                          mySensorData.print( " \t " );
                     Serial.println(" Wrong passwowrd!");


It's not clear if the "Password" object will let you read out the current password attempt. The Password object seems designed to hold a single password and to allow you to check the keypad entry against that one fixed password. Right now you seem to be checking the keypad entry against "1234". You either have to find out how to get the keypad entry from the Password object or abandon the Password object and store the keypad entry in something like a character array.

However you get the password attempt you want to compare it with the password field from each record in the file. A string comparison (strcmp()) should work. You can either use the readUntil() function to read the file up to each comma and store the fields in separate buffers or store the whole line in one buffer and use a function like strtok() (string tokenize) to separate the line into fields.

Yes, I used a fixed password just for testing the comparison.

But, sorry, I'm new in programming and I didn't understand readUntil() function.

How it works ?? and when it reaches the Comma will it jump to the next line automatically ??

Thank you.

It moves bytes from the file to the buffer until a delimiter is reached. You would use ',' for all of the fields up to the last and then use '\n' or '\r'. Read each field into a separate buffer so when you find a matching password you will have all the other data handy.