Question

Part 1: Is this Crazy Password Valid? A good password (in this strange system) should have...

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 don’t care about numbers 1, 2, 3, 4. If it contains 1, 2, 3 or 4, we don’t 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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#validator.py

import hw4_util
def ruleOne(passwd):
   if(len(passwd) <=25 and len(passwd)):
       return True
   else:
       return False
def ruleTwo(passwd):
   passwd = passwd.lower()
   for common in passwds:
       if(common == passwd):
           return False
   return True

def ruleThree(passwd):
   if((passwd.find('@') == -1 and passwd.find('$') == -1) or passwd.find('%')!=-1):
       return False
   else:
       return True
def ruleFour(passwd):
   upper = False
   lower = False
   numRange = False
   valid = True
   for char in passwd:
       if(char.isupper()):
           upper = True
       elif(char.islower()):
           lower = True
       elif(char.isnumeric()):
           if(char >='1' and char <= '4'):
               numRange = True
           else:
               numRange = False
               valid = False
               break
   if(valid == False):
       return False
   elif(upper and lower):
       return True
   elif(numRange == True):
       return True
   else:
       return False

def ruleFive(passwd):
   pre = ''
   for char in passwd:
       if(pre !=''):
           if(char != '_'):
               return False
           else:
               pre = ''
       if(char.isupper()):
           pre = char
   if(pre.isupper()):
       return False
   return True

def ruleSix(passwd):
   for char in passwd:
       if(char.isnumeric()):
           if(char < '1' or char >'4'):
               return False
   return True

total_lists = hw4_util.get_number_of_password_lists() - 1
pos = int(input("Select the number of common passwords by entering a number between 0 and "+str(total_lists)+" => "))
if(pos > total_lists):
   print("Invalid input given")
   exit()
passwds = hw4_util.get_password_list(pos)

choice = ''
while(choice !='q'):
   passwd = input("Enter a password => ")
   print(passwd)
   one = ruleOne(passwd)
   two = ruleTwo(passwd)
   three = ruleThree(passwd)
   four = ruleFour(passwd)
   five = ruleFive(passwd)
   six = ruleSix(passwd)
  
   valid = one and two and three and four and six
   if(one):
       print("Rule 1 is satisifed")
   else:
       print("Rule 1 is not satisifed")
  
   if(two):
       print("Rule 2 is satisifed")
   else:
       print("Rule 2 is not satisifed")
  
   if(three):
       print("Rule 3 is satisifed")
   else:
       print("Rule 3 is not satisifed")
  
   if(four):
       print("Rule 4 is satisifed")
   else:
       print("Rule 4 is not satisifed")
  
   if(five):
       print("Rule 5 is satisifed")
   else:
       print("Rule 5 is not satisifed")
  
   if(six):
       print("Rule 6 is satisifed")
   else:
       print("Rule 6 is not satisifed")
  
   if(valid):
       print("password is valid")
   else:
       print("A suggested password is : "+passwd[:3] + "42" + passwd[-3:])
  
   choice = input("Enter q to quit, Any key to continue")

#hw4_util.py
pass_lists = ["top25.txt","top100.txt"]
def get_number_of_password_lists():
   return len(pass_lists)
def get_password_list(index):
   f = open(pass_lists[index],"r")
   line = f.readline()
   passwds = []
   while(line):
       line = line.strip().lower()
       passwds.append(line)
       line = f.readline()
   f.close()
   return passwds

Add a comment
Know the answer?
Add Answer to:
Part 1: Is this Crazy Password Valid? A good password (in this strange system) should have...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I have a python project that requires me to make a password saver. The major part...

    I have a python project that requires me to make a password saver. The major part of the code is already giving. I am having trouble executing option 2 and 3. Some guidance will be appreciated. Below is the code giving to me. import csv import sys #The password list - We start with it populated for testing purposes passwords = [["yahoo","XqffoZeo"],["google","CoIushujSetu"]] #The password file name to store the passwords to passwordFileName = "samplePasswordFile" #The encryption key for the caesar...

  • Password Validation Write a program called PasswordValidationYourLastName that validates a new password, following these guidelines: Must...

    Password Validation Write a program called PasswordValidationYourLastName that validates a new password, following these guidelines: Must be at least 8 characters Must have at least 1 uppercase letter Must have at least 1 lowercase letter Must have at least 1 digit Write a program that asks for a password, and then asks again to confirm it (you can use the scanner or JOptionPane). Pass those two Strings to a method called validatePassword( ). Your validatePassword( ) should return a boolean...

  • Convert this code written in Python to Java: username=input("please enter a username") password=input("please enter a password:")...

    Convert this code written in Python to Java: username=input("please enter a username") password=input("please enter a password:") def is_a password(password):     count_uppercase, count_lowercase= 0, 0     for characters1 in password:         if characters1.isupper():         count_uppercase += 1         if characters1.islower():         count_lowercase += 1     is_password is good = True     if len(password) <= 7:         print "Passwords must be at least 8 characters long"     is_password is good = False     if count_uppercase < 1:         print "Your password must...

  • Write a program that asks the user to enter a password, and then checks it for...

    Write a program that asks the user to enter a password, and then checks it for a few different requirements before approving it as secure and repeating the final password to the user. The program must re-prompt the user until they provide a password that satisfies all of the conditions. It must also tell the user each of the conditions they failed, and how to fix it. If there is more than one thing wrong (e.g., no lowercase, and longer...

  • please help me out and input values please .. main cpp.. please follow intructions exactly witj...

    please help me out and input values please .. main cpp.. please follow intructions exactly witj clarity please CSE 110-Intro to Computer Programming Project #3 Requirements-String Class Functions and Test Case Documentation Using the String Class, design and develop a multi-file password validation program and Test case Document (10% of grade) that requests a password, and validates it based on the following criteria. The password must be at least 8 characters long, contain at least one number, and at least...

  • A hacker has programmed their computer to generate, uniformly at random, an eight-character password, with each...

    A hacker has programmed their computer to generate, uniformly at random, an eight-character password, with each character being either one of 26 lower-case letters (a-z), one of 26 upper-case letters (A-Z) or one of 10 integers (0-9). The hacker wants to infiltrate a website that has 2 million users. Assume, for simplicity, that each user is required to use a unique password. i. What is the expected number of attempts before the hacker successfully generates a user password? ii. What...

  • Write the Code in C program. Create a random password generator that contains a user-specified number...

    Write the Code in C program. Create a random password generator that contains a user-specified number of characters. Your program should prompt the user for the desired length of the password. Length of password: To create your password, use the random number generator in the stdlib.h C library. To generate random numbers, you will need the srand() and rand() functions. srand(seed) is used to "seed" the random number generator with the given integer, seed. Prompt the user for the seed...

  • 8.4 in python function that checks whether a string is a valid password. Suppose the pas...

    8.4 in python function that checks whether a string is a valid password. Suppose the pas rules are as follows: . A password must have at least eight characters - A password must consist of only letters and digits. ■ A password must contain at least two digits. Write a program that prompts the user to enter a password and displays valid password if the rules are followed or invalid password otherwise (Occurrences of a specified character) Write a function...

  • Please make this Python code execute properly. User needs to create a password with at least...

    Please make this Python code execute properly. User needs to create a password with at least one digit, one uppercase, one lowercase, one symbol (see code), and the password has to be atleast 8 characters long. try1me is the example I used, but I couldn't get the program to execute properly. PLEASE INDENT PROPERLY. def policy(password): digit = 0 upper = 0 lower = 0 symbol = 0 length = 0 for i in range(0, len(password)): if password[i].isdigit(): # checks...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT