Question

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 than 15 characters), the program must print out all of the things that are wrong, and how to fix them.

The program follows these rules for passwords:

  1. The password must contain at least one lowercase letter.

  2. The password must contain at least one uppercase letter.

  3. The password must be between 6 and 20 characters, inclusive.

    a. If the password is between 6 and 13 characters, inclusive, it must contain a “7” somewhere in the password.

    b. If the password is between 14 and 20 characters, inclusive, itmust contain a “2” somewhere in the password.

  4. The password cannot contain the characters “0” and “O” (zero anduppercase o) at the same time. (It can contain a “0” or an “O”, just notboth at the same time. It may also contain neither.)

For this part of the homework, you must have an in-line comment at the top of each of your program’s individual if, elif, and else statements, explaining what is being checked by that conditional.

(HINT: Think carefully about what your conditionals should look like. If necessary, draw a truth table to help figure out what different inputs will do. Using a Boolean flag will also likely make this easier.)

(See the next page for sample output.)

Here is some sample output for hw4_part3.py, with the user input in blue. (Yours does not have to match this word for word, but it should be similar.)

linux1[8]% python hw4_part3.py
Please enter a password: dogs
Password must have an uppercase character
Password must be at least 6 characters
Please enter a password: DOGS
Password must have a lowercase character
Password must be at least 6 characters
Please enter a password: Dogs
Password must be at least 6 characters
Please enter a password: Doggos
Shorter passwords must contain a 7
Please enter a password: 7Doggos
Thank you for picking the secure password 7Doggos

linux1[9]% python hw4_part3.py
Please enter a password: thisMustBeSecureItsLongAlso27Password must be no longer than 20 characters
Please enter a password: abcdefghijklmnopqrst
Password must have an uppercase character
Longer passwords must contain a 2
Please enter a password: 2and7EQUALSnine
Thank you for picking the secure password 2and7EQUALSnine

linux1[10]%  python hw4_part3.py
Please enter a password: O_and_0
Shorter passwords must contain a 7
Password cannot contain a O and a 0 at the same time
Please enter a password: O_and_7
Thank you for picking the secure password O_and_7

linux1[11]% python hw4_part3.py
Please enter a password: greatPassword7!
Longer passwords must contain a 2
Please enter a password: greatPassword2!
Thank you for picking the secure password greatPassword2!

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

Make sure code is indented.

import re

def validate():

while True:

password = input("Enter a password: ")

if len(password) < 6 or len(password) > 20:

print("Password should be greater than or equal to 6 and less than or equal to 20")

validate()

elif len(password) >= 6 and len(password) <= 13:

if password.find("7") == -1:

print("It should have 7")

validate()

else:

r_p = re.compile('^(?=\S{6,20}$)(?=.*?\d)(?=.*?[a-z])(?=.*?[A-Z])(?=.*?[^A-Za-z\s0-9])')

if re.search(r_p, password):

print("Valid")

break

else:

print("Invalid!")

validate()

validate()

Add a comment
Know the answer?
Add Answer to:
Write a program that asks the user to enter a password, and then checks it for...
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
  • in C++, Design a program that asks the user to enter a password, and then analyze...

    in C++, Design a program that asks the user to enter a password, and then analyze the password, and then analyze the password for the following weaknesses: 1. Fewer than 8 characters 2. Does not contain at least one uppercase letter and one lowercase latter 3. Does not contain at least one numeric digit 4. Does not contain at least one special character( a character that is not a letter or numeric digit) 5. Is a sequence of consecutive uppercase...

  • Create a Python Program that will ask the user for a password (use input) Verify that...

    Create a Python Program that will ask the user for a password (use input) Verify that the password meets the following conditions: -must be 12 characters long -must have uppercase and lowercase -must contain at least 1 special character (!~#$%^&*{}+_) -must be a mix of numbers and letters You must do this only using regular expressions so for instance this will not be accepted if len(password) <12: At the end of the program tell the user their password is ok...

  • Create a Python Program that will ask the user for a password (use input) Verify that...

    Create a Python Program that will ask the user for a password (use input) Verify that the password meets the following conditions: -must be 12 characters long -must have uppercase and lowercase -must contain at least 1 special character (!~#$%^&*{}+_) -must be a mix of numbers and letters You must do this only using regular expressions so for instance this will not be accepted if len(password) <12: At the end of the program tell the user their password is ok...

  • Write a program that inputs a string from the user representing a password, and checks its...

    Write a program that inputs a string from the user representing a password, and checks its validity. A valid password must contain: -At least 1 lowercase letter (between 'a' and 'z') and 1 uppercase letter (between 'A' and 'Z'). -At least 1 digit (between '0' and '9' and not between 0 and 9). At least 1 special character (hint: use an else to count all the characters that are not letters or digits). -A minimum length 6 characters. -No spaces...

  • 4: A certain computer program is accessed by entering a user-defined password. If the password a. can contain any lo...

    4: A certain computer program is accessed by entering a user-defined password. If the password a. can contain any lowercase letter, uppercase letter, or digit from 0-9, and must contain 10 characters, how many possible passwords are there if no character can be used more than once? Express your answer as a factorial statement. Is 8 an example of permutations or combinations? b. 4: A certain computer program is accessed by entering a user-defined password. If the password a. can...

  • 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...

  • 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...

  • Python Create a function that checks user input in an attempt to create a password. The...

    Python Create a function that checks user input in an attempt to create a password. The valid_password function accepts a password as an argument and returns either true or false to indicate whether the password is valid. A valid password must be at least 7 characters in length, have at least one uppercase letter, one lowercase letter, and one digit. Respond with output to the user as to whether the password is valid or not, and allow the user to...

  • C++: Imagine you are developing a software package that requires users to enter their own passwords....

    C++: Imagine you are developing a software package that requires users to enter their own passwords. Your software requires that users’ passwords meet the following criteria: -The password should be at least six characters long. You can set the maximum size and let the user know -The password should contain at least one uppercase and at least one lowercase letter. -The password should have at least one digit. Write a program that asks for a password into a c-string and...

  • Lang: Python Create code that will generate a random password for a user following the constraints...

    Lang: Python Create code that will generate a random password for a user following the constraints below... Password Generator: Must have a length of 20 Must contain 2 lowercase letters Must contain 2 uppercase letters Must contain 2 numbers Must contain 2 valid symbols These symbols are allowed !@#$%^&*()? Chose the characters with replacement

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
ADVERTISEMENT