Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 1: Is this Crazy Password Valid? A good password (in this strange system) should have the following properties: Rule 1: The password should be

Part 1: Is this Crazy Password Valid?
A good password (in this strange system) should have the following properties:
Rule 1: The password should be between 4 and 25 characters inclusive, starting with a letter.
Rule 2. The password should not be contained in a list (selected by the user) that contains passwords commonly used by many people thus making these passwords easy to guess. Comparisons with passwords from the list of common passwords should be case insensitive. For example, if the password entered by the user is P@sSw0rD and there is a common password p@ssw0rd in the list, Rule 2 is not satisfied.
Rule 3. The password should have at least one of the following characters @ $ and no %.
Rule 4: The password should have at least one upper and one lower case character, or it should contain at least one of 1, 2, 3 or 4. If it contains upper and lower case characters, we dont care about numbers 1, 2, 3, 4. If it contains 1, 2, 3 or 4, we dont care about upper or lower case characters.
Rule 5: Each upper case character (if there is any) must be immediately followed by at least one underscore symbol (_). Rule 6: Each numerical digit, if there is any, must be less than 5. (So, pa$$35 is not valid because of 5.) Note that in Rule 4 you checked the existence of at least one number in the 1-4 range, now you want to check that all numbers are in this range. Write a program that validates a password entered by the user against this set of rules. The program should first determine the number of available lists with common passwords (as described below), prompt the user to enter a correct number to select the list, and then ask for a password. If the password is a valid one (satisfying all the above rules), print a corresponding message to the user. If the password is not valid but satisfies Rule 1, suggest a valid password by taking the first 3 and the last 3 characters and appending 42 between them (note the password constructed this way may not be valid with respect to the above rules, but randomness is always good for security). Otherwise, report the password as not valid. In order to check the password against Rule 2, you will first need to determine how many lists with common passwords are available to you. Use function get_number_of_password_lists() provided in hw4_util module. Make sure you have your code for this part of the assignment, the hw4_util.py file, and two data files, password_list_top_25.txt and password_list_top_100.txt, all residing in the same directory. If everything is set up correctly, the following code: import hw4_util lists_count = hw4_util.get_number_of_password_lists() print(lists_count) should print 2, indicating that you have 2 lists (numbered 0 and 1) with common passwords available to you. You can obtain any of these lists by using get_password_list() function from the hw4_util module and specifying the list number, as in the following example (we slice the list to only show the first 5 items for brevity): import hw4_util passwords = hw4_util.get_password_list(0) print(passwords[0:5]) which outputs ['123456', 'Password', '12345678', 'qwerty', '12345']. Note that when you submit your code on Submitty we will be using lists of common passwords which are different from the ones we provide to you, and we will be using more than two lists. Your code should not hardcode the number of lists available or the contents of the lists. Instead, use functions get_number_of_password_lists() and get_password_list() from hw4_util.
Hint: A very good way to solve this problem is to use booleans to store whether each rule is satisfied or not. Start slowly, write and test each part separately. Rules 1, 3, and 4 do not require looping at all. For Rule 2, you will need to loop through all items in the list of common passwords. For Rule 5, the simplest solution involves looping through the string once. The same is true for Rule 6. To construct the suggested password, you only need one line of code by using slicing. There are some really useful string functions you can use: str.islower(), str.isupper() and of course str.count() and str.find(). Try help(str) to learn more about them. Here is an example solution that involves using booleans to store the result and building on them: is_long_enough = len(word) <= 25 and len(word) >= 4 is_lowercase = word.islower() if is_long_enough and is_lowercase: print ("It is long enough and lower case")
Example:
Select the list of common passwords by entering a number between 0 and 1 => 0
0
Enter a password => this_is_#lowercase
this_is_#lowercase
Rule 1 is satisfied
Rule 2 is satisfied
Rule 3 is not satisfied
Rule 4 is not satisfied
Rule 5 is satisfied
Rule 6 is satisfied
A suggested password is: thi42ase

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2017 For Windows Web And Database Applications

Authors: Corinne Hoisington

1st Edition

1337102113, 978-1337102117

More Books

Students also viewed these Databases questions