Day 8 Task 03 Consistency check

Task 03. Check Member Features

Block account security weaknesses like duplicate sign-ups and unsafe email validation.

Task 03 Task 03 Check Member Features Lab Guide

📥 Lab input

  • • day8_user_service.js

💾 Lab output

  • • day8_robust_user_service.js

1. Story and lab background

After testing the sign-up and login buttons, a happy developer declared, "It all works perfectly!" But the next day a serious data consistency incident happened. A user 'double-clicked', sending two sign-up queries to the server in a row, and two member accounts with the same email were created side by side in the database. This completely tangled the booking history on My Page, and weak email format checks and temporary password session handling left accounts open to takeover.

2. Learning goals

  • Diagnose the storage weakness where data consistency breaks on multiple sign-ups with the same email, and set up a guard.
  • Add a Regex validation guard to the JavaScript that filters out invalid email patterns.
  • Secure accounts through AI auditing and get solid improved code with error handling and duplicate checks.

3. Download the lab starter code

Copy or download the JavaScript skeleton below and save it in your local lab path (day8_user_service.js).

javascript// day8_user_service.js (weak member management skeleton script)
const userDatabase = [];

function registerUser(email, password, nickname) {
  // TODO: add a duplicate sign-up guard and an email regex validation guard to protect account integrity.
  const newUser = {
    email: email,
    password: password,
    nickname: nickname,
    status: 'active'
  };
  userDatabase.push(newUser);
  return { success: true, user: newUser };
}

function loginUser(email, password) {
  const user = userDatabase.find(u => u.email === email);
  if (!user) {
    return { success: false, message: "That username does not exist." };
  }
  if (user.password !== password) {
    return { success: false, message: "The password does not match." };
  }
  return { success: true, message: "Login successful", user };
}

4. Codex AI Prompt Card

Copy the prompt below, paste it into the Codex Client AI chat and get guidance.

Audit the provided `day8_user_service.js` sign-up and login script, find defects such as 1) the risk of missing duplicate sign-up checks and 2) immediately discarding the old password when it's forgotten, and suggest a final improved JavaScript version with validation guards that make the service more stable.
← Previous step Next step →