NodeJS / Authentication - Hashing a User's Password

This technical problem deals with creating a password hash for a user object in NodeJS.

Problem

Given a user object with the following properties:
- id
- name
- email
- password
Write a function that will take in a user object and return an object with the following properties:
- id
- name
- email
- passwordHash
The passwordHash property should be a hash of the password property on the user object.
Example input: 
const user = {
  id: 1,
  name: 'John Doe',
  email: 'john.doe@example.com',
  password: 'password123'
}
Example output: 
const user = {
  id: 1,
  name: 'John Doe',
  email: 'john.doe@example.com',
  passwordHash: '5f4dcc3b5aa765d61d8327deb882cf99' // password123
}

Solution

This solution is in JavaScript. Our A.I. can create solutions in multiple languages.
by kayakane
const user = {
  id: 1,
  name: 'John Doe',
  email: 'john.doe@example.com',
  password: 'password123'
}

const hashPassword = (user) => {
  const { password, ...rest } = user;
  const passwordHash = md5(password);
  return { ...rest, passwordHash };
}

console.log(hashPassword(user));

A.I. Evaluation of the Solution

The candidate's solution correctly generates a hash of the password property on the user object, and returns an object with the remaining properties. This solution correctly solves the problem.

Evaluated at: 2022-11-20 00:17:23