easyPasswordsIdentity
Password Policy Checker
Check a new password against a modern, NIST-style policy: length, common passwords, long repeats and the username, and report every rule it breaks.
JavaScript or Python
Implement a password check in the spirit of current guidance, which favours length and blocklists over forced symbols. Given a password and a username (ASCII strings), return the list of problems, in this order:
"too_short": fewer than 12 characters"common": the password, ignoring case, is one ofpassword, 123456, 123456789, qwerty, letmein, admin, welcome, iloveyou"repeats": the same character 4 or more times in a row"contains_username": the username is at least 3 characters and appears inside the password, ignoring case
Return an empty list for a password with no problems.
Examples
Example 1
Input: password = "qwerty", username = "asha" Output: ["too_short", "common"] Why: Six characters, and on the common list
Example 2
Input: password = "correct horse battery", username = "asha" Output: [] Why: Long, uncommon, no long repeats, no username
Constraints
0 <= password.length <= 2560 <= username.length <= 64- ASCII characters only
Hints
Hint 1
Check each rule independently and append in the stated order.
Hint 2
For repeats, track the length of the current run of identical characters.
Solution
Show the solution (try it yourself first)
Each rule is independent, so check them in order and collect the failures. The only loop is the run-length check, which resets the counter whenever the character changes and stops at the first run of four.
def password_issues(password, username):
common = {"password", "123456", "123456789", "qwerty", "letmein", "admin", "welcome", "iloveyou"}
issues = []
if len(password) < 12:
issues.append("too_short")
if password.lower() in common:
issues.append("common")
run = 1
for i in range(1, len(password)):
run = run + 1 if password[i] == password[i - 1] else 1
if run >= 4:
issues.append("repeats")
break
if len(username) >= 3 and username.lower() in password.lower():
issues.append("contains_username")
return issuesComplexity
Time O(n + m) for the password and username lengths, space O(1). The design reflects NIST SP 800-63B: prefer long passphrases, block known-bad and breached passwords (in production, check a large breached-password list such as a k-anonymity API rather than eight words), and avoid composition rules and forced periodic changes that push users towards predictable patterns. Expect that trade-off as the follow-up question.
Found a mistake in this problem, its tests or the solution?