# Password Validation
The goal of this assignment is to familiarize you with loops. In Part 1, you
will practice various different types of loops. In Part 2, you will implement
a program to help a user choose a strong password.
| Part | Section |
|---------------|-----------------------------------------------|
| 1 (in-lab) | [Practice with Loops](#part1) |
| 1 (in-lab) | [Check-in Instructions](#checkin) |
| 2 (lab/home) | [Password Validation](#part2) |
| 2 (lab/home) | [Submission Instructions](#submission) |
## Part 1: Practice with Loops
This lab will give you practice using different types of loops.
#### Getting started
Create a new project named `PasswordChecking` in the `CSCI051p-Workspace` you
created on your Desktop. *Double check that you are creating the project in the
right place, or you will likely have trouble finding your files later.* Then
download the [starter file](loops.py) for part one, `loops.py`, and copy it into the
(recently created) `CSCI051p-Workspace/PasswordChecking` folder. If you don't
see the new file, ask PyCharm to rescan that folder by clicking the triangle
next to that folder (on the left-side list) to close and re-open it. The newly
added `loops.py` should now be visible. If you double-click it (in the
left-side list), that file should appear in the main editing window.
Inside the file you should see three problems, each followed by a single-line
comment `# TODO`. Replace each of these `# TODO` comments with a solution to
that problem.
#### Problem 1
Implement Python code that asks the user to choose their favorite primary color
(red, yellow, or blue) and counts how many tries it takes them to choose a
color. You must use a while-loop to solve this problem. It is fine to ignore
capital letters.
##### Sample Run
```
What is your favorite primary color: red, yellow, or blue?
green
That is not a primary color. What is your favorite primary color?
13
That is not a primary color. What is your favorite primary color?
red
You chose red after 3 tries.
```
#### Problem 2
Implement Python code that asks the user for two positive integers and then
prints the sum of the even numbers between those integers. If one of those
integers is an even number, you should include that value. For this problem,
you may assume that your user correctly follows instructions. You must use a
for-loop to solve this problem.
##### Sample Run
```
Enter an integer:
1
Enter another integer
10
The sum of the even numbers in the range [1, 10] is 30
```
#### Problem 3
Implement Python code that asks the user for a string and then counts the
number of vowels (a, e, i, o, or u) that appear in that string. You may assume
that the user uses only lower case letters. You must use a for-loop to solve
this problem
##### Sample Run
```
Enter a string:
Hello there
"Hello there" contains 4 vowels
```
#### Checking In
Find a TA or your lab instructor and demo your code. They will look over your
code, ask you to run your code with various different inputs, and award you
points for Part 1.
This must be completed before leaving the lab.
After that you should start working on Part 2.
## Part 2: Password Checking
#### Background Information
A new startup, CoolGamzRUs, needs its users to choose a username and password
when they create a new account. However, CoolGamzRUs would like to make sure
that its users do not choose weak passwords (like `123456`), so it would like
to enforce certain rules about what passwords may be chosen. They hire you to
write a program that will help its users choose a strong password.
#### Specification
You will write an interactive program that helps a user to choose a password.
The program will prompt the user to enter a password. If the user enters a
strong password, the problem will tell the user that it is a valid password. If
the user enters a weak password, the program will tell the user that it is a
weak password and tell the user what is wrong with their password. And then
ask the user to enter a new password. It will keep asking the user to enter a
password until the user enters a strong password.
CoolGamzRUs defines a strong password as follows:
* Password should contain at least 8 characters
* Password should contain at least 2 lowercase letters
* Password should contain at least 1 uppercase letter
* Password should contain at least 2 numbers
* Password should contain at least 1 of the characters !@#$
If the user enters a password that passes all five rules, the program should
print `Password is a valid password` and then finish.
If the user enters a weak password, the program should print the first rule
that the password fails (using the order given above) and then ask the user to
enter another password. A sample run is given below.
__Note: your program must match the wording and formatting of the sample run
exactly. We will use programs to check your program for correctness, and our
grading program will only give you credit if you use the correct wording and
spacing. Please double check this, and talk to an instructor or TA if you are
unsure.__
#### Sample Run
```
Please enter your password:
123456
Password should contain at least 8 characters
Please enter your password:
12345678
Password should contain at least 2 lowercase letters
Please enter your password:
password
Password should contain at least 1 uppercase letter
Please enter your password:
Password
Password should contain at least 2 numbers
Please enter your password:
fall2019
Password should contain at least 1 uppercase letter
Please enter your password:
Fall2019
Password should contain at least 1 of the characters !@#$
Please enter your password:
Fall2019!
Password Fall2019! is a valid password
```
#### Getting Started
There is a starter file `password_checking.py` provided for this assignment.
Download the [starter file](password_checking.py) and copy it into the (recently created)
`CSCI051p-Workspace/PasswordChecking` folder.
#### Hints and Suggestions
You will probably need to use two nested loops to implement this program: one
loop to prompt the user to enter another password until they enter a strong
password and one loop to go through the string the user entered and check
whether it is a strong password. Think about whether you want to use a
while-loop or a for-loop for each of these pieces.
Recall that relational operators `<`, `<=`, `>`, `>=` work on strings. These
operators compare strings using lexicographic order, what you might think of as
the order words appear in a dictionary. So `"aaa" < "ab"` and `"ab < ac"`.
Note that in Python, like in most other programming languages, any upper case
letter is considered "less than" any lower case letter. So `"aBc" < "aaa"`.
#### Coding Style
Make sure that your program is properly commented:
* You should have a multi-line comment atthe very beginning of the file stating
your name, course, assignment number and the date.
* You should include meaningful one-line comments that explain what your code
is doing
In addition, make sure that you have used good style. This includes:
* Following naming conventions, e.g. all variables and functions should be
lowercase.
* Using good (mnemonic) variable names.
* Proper use of whitespace, including indenting and use of blank lines to
separate chunks of code that belong together.
For more detailed descriptions, please review the [Python Coding Style Guidelines](../../python_style.html).
## Part 3: Feedback
Create a file named `feedback.txt` that answers the usual questions:
1. How long did you spend on this assignment?
2. Any comments or feedback? Things you found interesting? Things you found
challenging? Things you found boring?
## Submission
For this lab you are required to submit two files:
- `password_checking.py` a python file that validates the user input password.
- `feedback.txt` a text file containing your feedback for this assignment.
These should be submitted using
[submit.cs.pomona.edu](http://submit.cs.pomona.edu)
as described in the general [submission instructions](../../submit.html).
Note that we will deduct points if your files are incorrectly names, if
you do not include your name in the correct place, or if you do not include
both files in your last submission. Please double and triple check this before
submitting!
## Grade Point Allocations
| Part | Feature | Value |
|-----------|-------------------------------------------|-----|
| Lab | Check-in | 3 |
| | | |
| Execution | Outer loop condition is correct | 3 |
| Execution | Inner loop correctly handles 5 rules | 10 |
| Execution | Correctly responds to valid password | 2 |
| | | |
| Style | Correctly named file | 2 |
| Style | Files submitted together | 1 |
| Style | Correct file-level multi-line comment | 1 |
| Style | Good use of inline comments | 2 |
| Style | Good use of variable names | 2 |
| Style | Good use of whitespace | 2 |
| | | |
| Feedback | Completed feedback file submitted | 2 |