Task 03 Task 03 Practice guide for checking membership functions
📥 Practice Input
- •
day8_user_service.js
💾 Practice output (Output)
- •
day8_robust_user_service.js
1. Story and practice background
After testing the operation of the sign-up and login buttons, the delighted developer declared, 'It worked very cleanly!' However, a fatal data integrity incident occurred the next day. When a user 'double-clicks', a subscription query is sent to the server in succession, creating two member accounts with the same email address side by side in the database. As a result, the reservation history inquiry on My Page was completely disrupted, and the validity check of the registration email format and temporary password disposal session device were insufficient, exposing the user to the threat of account theft.
2. Learning objectives
- You can investigate vulnerabilities in subscription storage that break consistency when multiple subscriptions to the same email are made and set up a guard.
- A regular expression (Regex) validation guard that filters out incorrect email pattern injection can be installed in JavaScript scripts.
- Through AI auditing, you can ensure account security and obtain a solid improvement code with error handling and redundancy checking.
3. Download practice basic code
Copy or download the JavaScript framework source below and go to the local practice path (day8_user_service.js) and save it.
javascript// day8_user_service.js (vulnerable member management skeleton script)
const userDatabase = [];
function registerUser(email, password, nickname) {
// TODO: Add an anti-duplicate subscription 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: "The ID does not exist." };
}
if (user.password !== password) {
return { success: false, message: "Password does not match." };
}
return { success: true, message: "Login successful", user };
}
4. Codex AI Prompt Card
Copy and paste the prompt below into the AI question and answer window of Codex Client and receive guidance.
Please audit the provided `day8_user_service.js` membership sign-up and login script to identify defects such as 1) the risk of missing duplicate sign-up checks, 2) immediate discarding of existing passwords when passwords are lost, and suggest a final JavaScript improvement with reinforced effective guards to increase service stability.