Introduction
Weak passwords cause a large share of account break-ins. This checker scores each password with transparent rules, so users understand exactly why P@ssw0rd is weak and correct-Horse-battery-7 is strong. It never prints the full password, only a masked form.
Problem statement
Objectives
- Apply several independent rules and combine their scores
- Use Character methods and IntStream checks
- Detect runs and sequences in strings
- Present results with explanations rather than just a number
Features
- Length and variety scoring
- Common-password detection with leetspeak normalisation
- Repeated-character and sequence penalties
- Ratings, reasons and tips
- Masked output that never reveals the password
Concepts demonstrated
- String scanning
- Rule-based scoring
- Normalisation
- Records for results
- Privacy by design
System architecture
evaluate returns a Result record with the score, rating, notes and tips. It adds length and variety points, then normalises the password (lower case, leetspeak substitutions, letters only) to compare against the COMMON set. longestRepeat finds the longest run of one character; longestSequence checks consecutive characters against the alphabet, digits and the QWERTY row, forwards and backwards. Scores are clamped to 0–100.
Folder structure
Complete source code
src/Main.java
What each file does
- src/Main.java
- The scoring rules in
evaluate, the repeat and sequence detectors, masking and the report.
How to run it
Compile
Run
Test against the expected output
Expected output
Generated by running the project with tests/sample-input.txt. Your output should match tests/expected-output.txt exactly.
abc password123 P@ssw0rd Summer2026 aaaa1111BBBB qwerty!9Z correct-Horse-battery-7 Tr0ub4dour&3x!
Testing
- Run with
tests/sample-input.txtand compare withtests/expected-output.txt. P@ssw0rdis recognised as "password" after leetspeak normalisation and rated WEAK.qwerty!9Zis penalised both as a common password and as a 6-key keyboard sequence.correct-Horse-battery-7scores 100 because it is long and uses all four character types.
Common errors
P@ssw0rd isn't detected as a common password
Apply leetspeak replacements before removing non-letters; otherwise the 0 and @ are deleted first.
Scores go below zero
Clamp the final score with Math.max(0, Math.min(100, score)).
Possible improvements
- Load a larger common-password list from a file
- Estimate entropy in bits and time to crack
- Check against the user's name or e-mail
Additional challenges
- 1Detect dates such as 2026 or 1999.
- 2Suggest a stronger variant of the password.
- 3Detect repeated substrings like 'abcabc'.
Built and tested it yourself? Mark it to update your dashboard.