14. Live Password Checklist on Sign-Up
A sign-up form shows a checklist under the password field that ticks each rule off as the user types. A single true/false is not enough for that UI: the form needs to know which rules are still unmet.
Security also asked to block passwords that contain the user's own name or email username, a common pattern in leaked-password lists.
Your task:
Write getPasswordChecklist(password, user) and return the ids of the unmet rules, in this fixed order. A strong password returns [].
- "minLength": at least 8 characters
- "uppercase": at least one letter A-Z
- "lowercase": at least one letter a-z
- "number": at least one digit
- "symbol": at least one character that is not a letter, digit or space
- "noSpaces": no spaces or other whitespace
- "notPersonal": does not contain the user's name or email username
Rules for notPersonal:
- Build tokens from user.fullName (split on spaces) and the email's local part, the text before "@" (split on ".", "_", "-" and "+").
- Ignore tokens shorter than 3 characters.
- The rule fails when the password contains any token, ignoring case.
Examples
Example 1
- Input
password = "sara2026"
user = { fullName: "Sara Adel", email: "sara.adel@example.com" }
- Output
["uppercase", "symbol", "notPersonal"]
- Explanation
- No capital letter, no symbol, and it contains the first name "sara".
Solution
Write getPasswordChecklist. Tab indents (Esc then Tab leaves the editor), Ctrl/⌘ + Enter runs. Each run has a 3-second limit. Your code is saved in this browser.
Test Results
Click "Run Code" to test your solution.