Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In python: write a function that checks whether a string is a valid password, su

ID: 3864997 • Letter: I

Question

In python: write a function that checks whether a string is a valid password, suppose the password 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

Hints: use the following to help write the program

          -len( )

          - isalnum( )

          - isdigit( ) – can also be used for characters

Have the program:

Begin the program and each function with a comment.

Define a function to prompt the user for a password and return it to main( ).

Define a second function to check the password and return True if it is valid, else False. Call this from main( ), also.

Run your program with test cases demonstrating valid passwords and each of the following error cases, with appropriate error messages.

          Show multiple error messages for multiple infractions. See 5th test case below.

Use local variables, rather than global.

Use structured code (e.g., no unstructured exits from loops).

Test Cases:

          1) abcd1234 is valid.

          2) Password must be at least 8 characters long.

               abcd123 is invalid.    

          3) Password must have at least 2 digits.

               abcdefg8 is invalid.

          4) Password must be alphanumeric.

               abcd123* is invalid.

          5) Password must be at least 8 characters long.

              Password must have at least 2 digits.       

              Password must be alphanumeric.

              abc3* is invalid.

Explanation / Answer

import re

def inputPassword():
print ("Please enter a password ")

user_pw = input("Enter The password please ")
return user_pw
  
def passwordCheck(password):
if(len(password)!=8):
print("Password length must be 8")
elif password.isalnum():
if len([x for x in password if x.isdigit()]) < 2:
print("password must contain atleast 2 digit")
else :
print(password + " is valid")
  
else:
  
print(password + "password must be Alpha numeric ")
def main():

inputValue=inputPassword()
passwordCheck(inputValue)
#pwRegex()
  
main()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote