MCS 260 Intro to Computer Science Spring 2022

Project 2 Due in Gradescope by Wednesday, March 2 by 11:59pm

RESOURCES ALLOWED: This project is to be completed individually. The only resources you may use when completing the project are

� Material posted on the course Blackboard page

� The course textbook and “further resources” listed in the Syllabus

If you are unsure about whether a resource is allowed, then please ask your instructor. You should also consult the course syllabus for a further explanation of academic honesty.

WHAT TO SUBMIT: You will submit two Python files project2-create-<lastname>-<firstname>.py and project2-login-<lastname>-<firstname>.py to Gradescope where <lastname> and <firstname> are replaced with your last and first name, respectively.

The first lines of each of your files should include the following:

#<firstname> <lastname>

#MCS 260 Spring 2022 Project 2

#I hereby attest that I have adhered to the rules for projects as well as UIC’s

Academic Integrity standards while completing this project.

The rest of your file should perform the actions described below.

ACTIONS: 1. In the project2-create-<lastname>-<firstname>.py script, write a function

PasswordGenerator. This function will generate a password with the following conditions:

� the password should be between 4 and 8 characters long, with each length being equally likely to be chosen

� the only characters allowed in the password are upper and lower case vowels, so AEIOUaeiou

� adjacent characters of the password cannot be the same vowel; for example AEeoiu is not allowed since E and e are adjacent, and IoeaaUE is not allowed since a and a are adjacent.

2. Retrieve the two files UIN.txt and NetID.txt from Blackboard. Note that the ith line of UIN.txt is the UIN corresponding to the ith NetID listed in NetID.txt. In the

project2-create-<lastname>-<firstname>.py file, write a script that creates and returns a dictionary AllUsers where the key:value pair is as follows:

The key is the user’s UIN value as a string padded with 0’s at the beginning so that the UIN is seven characters long. For example, the first UIN is 571552, so the first key should be “0571552”.

The value associated to the key is a dictionary with two keys: “email” and “password”. The value associated to “email” should be the user’s NetID with @uic.edu added to the end. The value associated with “password” should be randomly generated using the PasswordGenerator function described in the step above.

3. Note that there are duplicate entries in the UIN.txt and NetID.txt files, so a user should not be added to the dictionary twice. If a second (or later) instance of the same UIN is encountered, it should be ignored (as well as the corresponding NetID). Only the first instance should be considered. IMPORTANT NOTE: Yes you could manually look through and remove the duplicates, but you must remove the duplicates as part of your program.

4. After your dictionary is created, you will write all of its data to a file called users.txt in the format described. Assume we have the following entry in AllUsers:

University of Illinois at Chicago page 1

 

 

MCS 260 Intro to Computer Science Spring 2022

AllUsers[UIN] = {

“email” = <user email>,

“password” = <user password>

}

For this UIN, you will print the following two lines of code (AND ONLY THESE TWO LINES) to the users.txt file:

<user email>

<user password>

5. Now we will talk about the project2-login-<lastname>-<firstname>.py file. You will prompt the user for their email (using input) and their password1 (again using input). You will then check the users.txt file to see if the credentials are proper. There are three cases that could happen:

(a) The email and password match for a user, in which case you will print “You have successfully logged in!”

(b) The email is in the file, but the password does not match, in which case you will print “That password does not match the email provided.”

(c) The email is not in the file, in which case you will print “That email is not in our system.”

Important Note: It is poor practice to give a user the print statements in parts (b) and (c) because you are potentially giving information to a hacker. In fact, in part (b) you’re telling them that the email they supplied is actually in the system. In part (c), you’re telling them that email is NOT in the system. A better solution, in any case where the user does not have proper credentials is to just tell them “Incorrect login. Please try again.” However, we are going to employ the method described in the three cases above, even if it is not a best practice.

6. ADD COMMENTS to clarify your choice of variables and to indicate what is happening at different steps of the program. A good rule of thumb is one line of comments for every four to five lines of code. Your comments will be checked to see that you understand how your code is structured and what it is doing in the big picture. Code lacking in comments will be penalized!

1The input function is not ideal for this purpose since it displays the user’s password as it is typed. A better option would be to use the getpass method of the getpass module which acts just like input except that it hides the typed input. You do not need to use this, but it is worth pointing out.

University of Illinois at Chicago page 2

Python Assistance 2