…
…
Write a password checker for a sign-up form: score by length and character variety, catch common and predictable passwords, build a suggestion text, and check the records that come in from the form in a batch.
Elena, the president of a student club, is preparing the club's new membership form. The old form had no rules for passwords; half of the members had typed 123456, qwerty, or their own name. This time Elena wants the form to score every password, reject the weak ones, and tell the user what to do.
You will build the rules step by step: length, uppercase letters, lowercase letters, digits, symbols, a list of commonly used passwords, and the username appearing in the password. At the end of the project, your program will check the records from the form like this:
Outputpriya.k 5/6 Strong ACCEPT
marco_34 0/6 Weak REJECT
zara.d 6/6 Very strong ACCEPT
noah.b 2/6 Weak REJECT
...
Accepted: 4 | Rejected: 4For a weak password, it will also write suggestions:
OutputCoffee2026: Medium
- 12 or more characters is stronger
- Add a symbol (like ! ? @ -)Lessons used: 4 (multiplying a string by a number), 6–8 (in, if/elif/else, and, the order of tiers, testing with boundary values), 10 (for over a string and over a list of values in square brackets), 12 (counters and building up a string), 14–16 (functions, return, parameters with default values, functions calling each other), 20 (slices), 21 (lower, strip, split, endswith), 22 (alignment with f-strings). Regular expressions (lesson 38) are not used; all the rules are built with string methods and conditions.
How to work: The seven cells build on each other: in each cell you write one or two functions, and later cells call them. In each cell the comments tell you what to do, and you write the code where it says ___. Run the cell, compare your output with the "Show expected output" area, then press Check. Check also tries your functions with other passwords besides the examples in the cell, especially at the boundaries (exactly 8 and exactly 12 characters, an empty password, a banned password written in uppercase).
This project is an exercise: on a real site, password checking also uses much longer banned lists and leaked-password databases, and passwords are never stored as plain text.
What you'll do
Code cells are for members
You can read the steps. Sign up free to run the code, complete the steps and save your progress.
The student club's new sign-up form asks for a password, and the club president, Elena, is tired of members typing "123456". You will write a password checker that runs behind the form.
The first job is to find out how many characters of each type a password has. The character groups are ready-made strings: UPPER, LOWER, DIGITS, SYMBOLS. count_chars(password, characters) should count how many of the password's characters appear in the characters string.
In a string, for gives one character per turn (lesson 10), in asks whether a character appears in a string (lesson 6), and the counter pattern is in lesson 12. One function counts all four groups, which is why it takes the group string as a parameter.
This step's code cell is for members.Sign up free
The first thing that makes a password strong is length: every extra character multiplies the work of guessing it by trial and error. Elena's rule:
Code cells are for members
You can read the steps. Sign up free to run the code, complete the steps and save your progress.
| Length | Score |
|---|---|
| 12 or more | 2 |
| 8–11 | 1 |
| shorter than 8 | 0 |
length_score(password) should return this score. A tiered rule needs an if/elif/else chain (lesson 7): start with the largest threshold and work down. The loop below tries passwords at the boundaries.
This step's code cell is for members.Sign up free
Length alone is not enough: aaaaaaaaaaaa is long but weak. Character variety matters too. For each of the four groups, if the password has at least one character from that group, it earns 1 point: uppercase, lowercase, digit, symbol. variety_score(password) should return a number from 0 to 4. What matters is whether the group is present, not how many characters it has: three digits and one digit both earn 1 point.
Then base_score(password) adds the length score and the variety score (0–6). Both functions call functions from earlier cells (count_chars, length_score); writing a function once and using it everywhere is the topic of lesson 16.
You need four separate if statements, not elif: a password can have both an uppercase letter and a digit, so each group must be asked separately.
This step's code cell is for members.Sign up free
Some passwords are weak no matter what their score is, because attackers try them first. weak_pattern(password, username="") should return True if any of these three cases applies, and False otherwise:
1. The password is in the BANNED list, ignoring uppercase and lowercase. Qwerty is just as banned as qwerty: use lower() before comparing (lesson 21). in also works on a list in square brackets: is the value in the list?
2. All characters are the same (zzzzzzzzzz). Hint: if you repeat the first character as many times as the password is long, do you get the password itself? (lessons 4 and 20)
3. A username was given and it appears inside the password, again ignoring case (Alex.2026 is weak for user alex).
username is a parameter with a default value (lesson 15): if it is not given, it is an empty string and rule 3 is skipped.
This step's code cell is for members.Sign up free
Put the pieces together. score_password(password, username="") should return 0 if the password is a predictable pattern, and the base score otherwise. level(score) should turn the score into the word Elena will show on the form:
| Score | Level |
|---|---|
| 6 | Very strong |
| 5 | Strong |
| 3–4 | Medium |
| 0–2 | Weak |
score_password does no new calculation; it calls the two earlier functions in the right order. Do not forget to pass the username on to weak_pattern.
This step's code cell is for members.Sign up free
Saying only "Weak" does not help the user; you need to tell them what to do. suggestions(password, username="") should return the suggestion lines as one string; each line starts with - , lines are separated by \n, and there is no empty line at the end. If there are no suggestions, it returns an empty string.
- This password is very common or easy to guess; choose a completely different one- Use at least 8 characters if it is shorter than 8, or - 12 or more characters is stronger if it has 8–11 characters; then, for each missing group, - Add an uppercase letter, - Add a lowercase letter, - Add a digit, - Add a symbol (like ! ? @ -)Build the text with the accumulate pattern (lesson 12): start with an empty string and add each suggestion to the end with \n; when you return, strip() (lesson 21) removes the extra line break at the end.
This step's code cell is for members.Sign up free
On the form's first day, Elena sent over the eight records that came in. Each line has the format username;password, but the spaces from the form have not been cleaned. The club's rule: a password with a score of 5 or more is ACCEPT, below that is REJECT.
check_record(line) should take a line and return the result line:
Outputpriya.k 5/6 Strong ACCEPTSplit the line into two parts with split(";"), clean each part with strip() (lesson 21), and score the password together with the username. Format: username :<10, score, level :<12, decision (lesson 22).
The loop below goes through all the lines; you increase the accepted and rejected counters. Check runs check_record on other lines too.
This step's code cell is for members.Sign up free