LESSON 11 · BEGINNER4 min read

Project: Password Strength Checker

Build a guided password checker that scores length and character variety, rejects obvious patterns, and explains its verdict.

ES2024 / Node.js 20+Free to readModule 2 of 19
YOUR NEXT SMALL WINS

By the end, you’ll be able to…

  • Combine string methods, conditions, and loops in one program.
  • Score a password with length and character-category checks.
  • Penalize obvious patterns and repeated characters.
  • Return a label with actionable reasons and test the result.

01Project brief

This project turns the module's string, number, conditional, and loop tools into a small password checker. It scores a password on length, uppercase and lowercase letters, digits, symbols, repeated characters, and obvious words or sequences. The result includes a label and a list of reasons. The samples at the end will show how each rule affects a real result.

Build the checker in password-checker.js. The function should accept one password string and return an object with label, score, and reasons. Keep the rules in one place so a future change, such as a longer minimum, is easy to make.

02Step 1: Start a score and collect reasons

Start with a score of zero and an empty reasons array. Each rule either adds a point or records an improvement. The first two rules reward length: eight characters earns one point, and twelve characters earns another. Short passwords receive a reason instead.

Notice that reasons explain what to improve rather than merely stating that the password failed. A list is more useful than one generic message because the learner can act on every item. Keep each message short and specific enough to guide a change.

password-checker.js⚡JavaScript
Ctrl + ↵
Output
Click Run or press Ctrl+Enter
Output will appear here after you run the code.

03Step 2: Inspect every character once

The character scan uses one loop and four boolean flags. A flag starts false and becomes true when a matching character appears. Checking each character once keeps the rules consistent and avoids running separate searches for every category.

The comparisons char >= "A" && char <= "Z" use character order to detect letters. Digits use the same idea. Symbols come from a string of allowed punctuation and includes. After the loop, each flag either adds a point or records a reason. Clear flag names make the final conditions easy to review.

password-checker.js⚡JavaScript
Ctrl + ↵
Output
Click Run or press Ctrl+Enter
Output will appear here after you run the code.

04Step 3: Apply penalties and print reports

The final rules handle obvious patterns and repeated characters. If the lowercase password contains password, 1234, or qwerty, the score is capped at two so a familiar sequence cannot earn a strong label. Three identical adjacent characters subtract a point.

After penalties, clamp the score between zero and six, choose a label, and add a success reason when the list is empty. The test block prints each sample, its score, and every reason, which makes the checker's decisions visible.

password-checker.js⚡JavaScript
Ctrl + ↵
Output
Click Run or press Ctrl+Enter
Output will appear here after you run the code.

05Review and acceptance checklist

Review the output against the brief. The function should handle a short password, a familiar pattern, a strong password, and a repeated character run. Each result should include a label, a score from zero to six, and reasons that match the deductions.

Check the boundary cases too: exactly eight characters, exactly twelve, and a password with no obvious pattern. If a rule changes, rerun every sample and compare the labels, not just the absence of errors. Write down the expected label and score for each sample before running the file, then compare. The project is complete when the reasons explain the score.

LET IT CLICK

The ideas worth keeping.

  • A checker is easier to trust when every deduction has a specific reason attached.
  • One character loop can collect several independent facts without repeating the string scan.
  • Pattern penalties and score clamping prevent a familiar or padded password from looking strong.
TURN UNDERSTANDING INTO SOMETHING YOU CAN DO

Make it yours.

Type and test your code right here in the interactive workspace. Run your solution, check the output, and compare with the worked guide when ready.

01

Exercise 1: Reject a username inside the password

Given username = "mira" and password = "Mira2024!", check the lowercase password for the username. Print a warning when it appears, otherwise print that no username was found.

your_turn_1.js⚡JavaScript
Ctrl + ↵
Output
Click Run or press Ctrl+Enter
Output will appear here after you run the code.
Explore a worked solution
one_possible_solution.jsJavaScript
const username = "mira";const password = "Mira2024!";if (password.toLowerCase().includes(username)) {  console.log("Avoid using your username in the password.");} else {  console.log("No username found.");}

Lowercasing the password makes the comparison case-insensitive, so Mira2024! still matches mira. The warning branch runs and the checker would subtract points for this input.

02

Exercise 2: Count digits and symbols

For password = "Tr0ub4dor&3", loop over the characters and count how many are digits and how many are symbols. Print both counts with labels.

your_turn_2.js⚡JavaScript
Ctrl + ↵
Output
Click Run or press Ctrl+Enter
Output will appear here after you run the code.
Explore a worked solution
one_possible_solution.jsJavaScript
const password = "Tr0ub4dor&3";const digits = "0123456789";const symbols = "!@#$%^&*()-_=+[]{};:,.<>?/";let digitCount = 0;let symbolCount = 0;for (const char of password) {  if (digits.includes(char)) digitCount++;  if (symbols.includes(char)) symbolCount++;}console.log(`Digits: ${digitCount}`);console.log(`Symbols: ${symbolCount}`);

The password contains the digits 0, 4, and 3 and the symbol &. The two counters therefore print 3 and 1 in that order.

A SMALL QUESTION. A USEFUL NEXT STEP.

What stayed with you?

Check the ideas while they’re fresh. Your answers stay in this page and feedback appears as you go.

A LITTLE ACTIVE RECALL0 / 3 answered
01Why does the checker return reasons as well as a label?
02Which sample receives the obvious-pattern penalty?
03Why does the repeated-character loop start at index 2?
⚡CODING CHALLENGE
🔒Required to Mark Lesson Complete

Exercise 1: Reject a username inside the password

Given username = "mira" and password = "Mira2024!", check the lowercase password for the username. Print a warning when it appears, otherwise print that no username was found.

EXPECTED OUTPUT
Avoid using your username in the password.
main.jsJavaScript
Ctrl + ↵
Execution Console
Click "Run & Verify" (or press Ctrl + Enter) to test your code against the challenge.

Keep exploring.

The official references behind this lesson, when you want a second angle or the full details.

MODULE 02 · PRACTICAL SELF-CHECK

Pause. Put the pieces together.

You’ve reached the end of Strings, Numbers & Decisions. Before moving on, use this task to check what you can do independently.

Build a password strength checker that explains its score and correctly handles empty, short, and mixed-character passwords.

Try it in your own environment and write down the result. This is a self-check; reading completion does not evaluate your code.

Review this module

One lesson closer.

Reading is a start. Trying it yourself makes the connection.

Solve the hands-on coding challenge in the knowledge section to verify your code and unlock lesson completion.