User Authentication in NodeJS

Write a function that takes in a user's email and password and returns true if the user exists in an array of user objects and the password is correct.

Problem

Given an array of user objects, write a function that takes in a user's email and password and returns true if the user exists in the array and the password is correct, false otherwise.
Example input:
var users = [
  {
    email: 'user1@example.com',
    password: 'password1'
  },
  {
    email: 'user2@example.com',
    password: 'password2'
  }
];
var email = 'user1@example.com';
var password = 'password1';
Example output:
true

Solution

This solution is in JavaScript. Our A.I. can create solutions in multiple languages.
by kayakane
var users = [
  {
    email: 'user1@example.com',
    password: 'password1'
  },
  {
    email: 'user2@example.com',
    password: 'password2'
  }
];
var email = 'user1@example.com';
var password = 'password1';

function checkUser(users, email, password) {
  for (var i = 0; i < users.length; i++) {
    if (users[i].email === email && users[i].password === password) {
      return true;
    }
  }
  return false;
}

console.log(checkUser(users, email, password));

A.I. Evaluation of the Solution

The candidate's solution correctly implements the function as specified in the question. It iterates through the array of users and returns true if it finds a match for the email and password.

Evaluated at: 2022-11-22 00:16:23