Assignment 2
Assignment 2
Introduction
Many websites and apps require you to create a password to register for, and log
in to, a personal account. Most of these platforms have restrictions on the
password you create so that it is not easy for hackers to crack. These restrictions
are usually based on the number of characters in the password and the different
groups of character types used in the password. Short passwords, such as
hello123, are easy to crack. Passwords with only one type of character (i.e. only
lowercase letters or only digits), such as 123456789, are also easy to crack. This is
why most websites and apps will require that you create a password that is long
and contains a variety of character types. They typically show you the "strength"
of the password you type in so that you know how safe your password is from
being hacked.
For this assignment, you will be creating a Python program to calculate the
strength of a password based on its length and number of groups of character
types used in the password. You must follow our instructions carefully to calculate
the strength of a given password. The way you implement the code is up to you
but it must follow the system explained below in the instructions to ensure your
code works as expected. Note that each platform has a slightly different way of
calculating password strength and the system used for this assignment is not
necessarily the same as that from anywhere else.
Files
For this assignment, you must create three (3) Python files named: password.py,
generate.py, and login.py. These three files must be saved in the same folder to
work correctly since login.py will need to access the other two files. Make sure
you name these files exactly as instructed including having them all lowercase.
Some example inputs and the expected outputs are provided later in these
instructions. You are also encouraged to test your program with many other
possible inputs to ensure that your code works in many different cases. Avoid
testing with any of your actual account passwords in case anybody sees them!
1) password.py
In the password.py file, you need to create two functions. One will calculate the
strength of a given password and the other one will be a helper function to count
the number of character groups used by the password. We will start with the
helper function and then call it from the strength calculator function.
First, define a function count_groups(pwd) which takes in a single parameter pwd
which is a String representing a password. The function must count and return
(this does not mean print it out) the number of character groups used in pwd. The
four character groups are depicted in Figure 1 below. Note that not all characters
are included in one of these four groups. For example, brackets/parentheses,
underscores, and special characters (i.e. é and ö) are not included in any group,
but they are still allowed to be used in passwords. Thus, it is possible that a
password could yield 0 groups if it consists only of characters that do not belong
to any of the four groups.
For example, count_groups("abc123") should return 2 because the password
"abc123" contains characters from 2 groups: lowercase letters and digits.
CS 1026A Assignment 2: Password Strength Due: Oct 23, 2024
2) generate.py
loop finishes. For more information on the random.choice() function, see the
official doc here: https://docs.python.org/3/library/random.html#random.choice
3) login.py
The third file you need to create is login.py. This file will be used to prompt the
user to create a new password or to use the password generator to randomly
generate a password. This file must import both of the previous files you created
so that the functions in those files can be called from this file. To link password.py
and generate.py to your login.py file, you must save all 3 files in the same folder
and include the following lines of code at the top of login.py:
from password import *
from generate import *
Note: you should not include any import lines in password.py or generate.py
(except for importing the "random" library in generate.py).
In login.py, implement a function called process_password(min_strength). In this
function, you must prompt the user for input within a loop that continues until
the user creates or randomly generates a password which has a strength of
min_strength or higher.
When the user types input, check if they typed a single X or x (either case) and if
so, generate a random password of length 15 using the generate_password
function you created in the generate.py file. If they did not enter X or x, then take
their inputted text as a possible password. Call the password_strength function
you created in the password.py file to check the strength of the user's new
password. If this strength is greater than or equal to min_strength, end the loop;
otherwise the loop must continue running to prompt the user for input again.
This file must display messages based on the user inputted password:
When the user is prompted for input, display a message that they must
type in a new password or type an X for a randomly generated password.
CS 1026A Assignment 2: Password Strength Due: Oct 23, 2024
Below are three examples of login.py input and output when running
process_password(3) (i.e. the min_strength parameter is 3 for these examples).
Example 1: the first password typed in has a strength greater than 3 so the
program terminates immediately without asking for a new password.
CS 1026A Assignment 2: Password Strength Due: Oct 23, 2024
Example 2: the user's first password is too weak so they are prompted to make a
new one. The second password contains a space making it have a strength of 0 so
they are prompted again to make a new one. The third attempt is successful as
the password's strength is greater than 3 so the program then terminates.
Example 3: the user's first password is too weak so they are prompted to make a
new one. The user then types X to indicate that they want a randomly generated
password. The random password is successful as the password's strength is
greater than 3 (these randomly generated passwords will always yield a strength
of at least 3 since they are 15 characters long; and they will usually have a
strength of 5 given the random character selection) so the program terminates.
Do not have function calls or any code outside of functions. Writing your code in
global space, outside of functions, will likely cause the autograder to fail and you
will not receive marks for those tests. Make sure your code is contained within
functions and that you do not leave any function calls at the bottom of your files.
Provided File
You are given a short file called driver.py which you can use to test that your files
are working correctly. Make sure you save driver.py in the same folder as the
other files. If you have any code in global space in your files, it will cause driver.py
to not run properly so remove or comment out any code in global space in your
files (except for import lines and global variables declared at the top).
CS 1026A Assignment 2: Password Strength Due: Oct 23, 2024
Rules
You may re-submit your code as many times as you would like. Gradescope
uses your last submission as the one for grading by default. There are no
penalties for re-submitting. However, re-submissions that come in after the
due date will be considered late and marked as 0, unless you have enough
late coupons remaining, in which case late coupons will be applied.
The top of each file you create must include your name, your Western ID,
the course name, the date on which you created the file (no need to
change it each time you modify your code), as well as a description of what
the file does. This information is required. You must follow this format:
"""
******************************
CS 1026 - Assignment X – Interest Calculator
Code by: Jane Doe
Student ID: jdoe123
File created: October 12, 2024
******************************
This file is used to calculate monthly principal and interest amounts for a
given mortgage total. It must calculate these values over X years using
projected variations in interest rates. The final function prints out all the
results in a structured table.
"""
Assignments will be run through a similarity checking software to check for
code that looks very similar to that of other students. Sharing or copying
code in any way is considered plagiarism and may result in a mark of zero
(0) on the assignment and/or reported to the Dean's Office. Plagiarism is a
serious offence. Work is to be done individually.
Submission
Marking Guidelines
IMPORTANT:
A mark of zero (0) will be given for tests that do not run on Gradescope. It is your
responsibility to ensure that your code runs on Gradescope (not just on your
computer). Your files must be named correctly, and you must follow all
instructions carefully to ensure that everything runs correctly on Gradescope.
A mark of zero (0) will be given for hardcoding results or other attempts to fool
the autograder. Your code must work for any test cases.