Question

Having a secure password is a very important practice, when much of our information is stored...

  1. Having a secure password is a very important practice, when much of our information is stored online. Write a program that validates a new password, following these rules:5 pts

  1. The password must be at least 8 characters long
  2. The password must have at least one uppercase and one lowercase letter
  3. The password must have at least one digit

The program must also ask for a user to enter it and then confirm it:

Enter your password:

Re-enter your password:

If the passwords don’t match or the rules are not fulfilled, a message is printed as to what the error is and the user is prompted again. Your program must include a function that checks whether the rules are passed and if the password is valid (returns True if it is valid):

      defisValidPassword(password)

Note: Re-enter password AFTER you validate the password first

  1. Your code with comments
  2. A screenshot of the execution

Test Cases:

            Abcdefgh – (should print “must have at least one digit”)

            1BCDEFGH – (should print “must have at least one lower case”)

            1abcdefgh – (should print “must have at least one upper case”)

            1Abcdef – (should print “must be at least 8 characters long”)

            1Abcdefg – (Valid: should ask to Re-enter password)

Python, keep it simple

Homework Answers

Answer #1

(I have provided the code with and without line comments and explained each line in line comments so that there will be no confusion for you. Please go through the code which you are comfortable in)

(Please open the screenshots in a seperate tab so that they are visible clearly.)

(If you still have any doubts regarding this answer please comment. I will definitely help. Thank you)

Code with line comments:

#validation function definition
def isValidPassword(passwd):
    #find length of password
    n = len(passwd)
    #initialize d, l,u to 0
    d = 0
    l = 0
    u = 0
    #find number of lower chars upper chars and digits in the password
    for i in passwd:
        if i.isdigit():
            d = d + 1
        if i.islower():
            l = l + 1
        if i.isupper():
            u = u + 1
    #check whether n<8 if yes print password must be 8 chars and
    #ask user to enter password again
    #for this we can just call main() function by which the user enters password again
    if (n < 8):
        print("password must be at least 8 characters long")
        main()
    #else check whether password has less than 1 lower char
    #if yes print password must have atleast one lower case and call main() function
    elif (l < 1):
        print("password must have at least one lower case")
        main()
    # else check whether password has less than 1 upper char
    # if yes print password must have atleast one upper case and call main() function
    elif (u < 1):
        print("password must have at least one upper case")
        main()
    # else check whether password has less than 1 digit
    # if yes print password must have atleast one digit and call main() function
    elif (d < 1):
        print("password must have at least one digit")
        main()
    #else return true. 
    # If all the above conditions fails.This condition executes and returns True
    else:
        return (True)

# main function
def main():
    #initially declare two strings passwd and re_pass
    passwd = ""
    re_pass = ""
    #input password
    passwd = input("Enter your password: ")
    #call the isValidPassword() function to validate the password
    validation_result = isValidPassword(passwd)
    #if the function returns true then print password is valid and
    #ask user to re type the password and print congrats message
    if (validation_result == True):
        print("Your password is Valid: ")
        print("Please Re-enter your password to confirm it")
    Re_pass = input()
    print("Congrats you created your password successfully")


if __name__ == "__main__":
    main()

Code without line comments:

def isValidPassword(passwd):
    n = len(passwd)
    d = 0
    l = 0
    u = 0
    for i in passwd:
        if i.isdigit():
            d = d + 1
        if i.islower():
            l = l + 1
        if i.isupper():
            u = u + 1
    if (n < 8):
        print("password must be at least 8 characters long")
        main()
    elif (l < 1):
        print("password must have at least one lower case")
        main()
    elif (u < 1):
        print("password must have at least one upper case")
        main()
    elif (d < 1):
        print("password must have at least one digit")
        main()
    else:
        return (True)


def main():
    passwd = ""
    re_pass = ""
    passwd = input("Enter your password: ")
    validation_result = isValidPassword(passwd)
    if (validation_result == True):
        print("Your password is Valid: ")
        print("Please Re-enter your password to confirm it")
    Re_pass = input()
    print("Congrats you created your password successfully")


if __name__ == "__main__":
    main()


Sample Testcase 1:

Enter your password: Abcdefgh
password must have at least one digit
Enter your password: 1BCDEFGH
password must have at least one lower case
Enter your password: 1abcdefgh
password must have at least one upper case
Enter your password: 1Abcdef
password must be at least 8 characters long
Enter your password: 1Abcdefg
Your password is Valid:
Please Re-enter your password to confirm it
1Abcdefg
Congrats you created your password successfully

Sample Testcase2:

Enter your password: jack123
password must be at least 8 characters long
Enter your password: jack123@
password must have at least one upper case
Enter your password: Jack123@
Your password is Valid:
Please Re-enter your password to confirm it
Jack123@
Congrats you created your password successfully

Code Screenshot with line comments:

Code Screenshot without line comments:

Sample Testcase1 Screenshot:

Sample Testcase2 Screenshot:

Know the answer?
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
Similar Questions
Imagine you are developing a software package that requires users to enter their own passwords. Read...
Imagine you are developing a software package that requires users to enter their own passwords. Read the input as a C-string or a string object. Your software requires that users’ passwords be sent to special functions that will verify if the characters used meet the following criteria: The password should be at least six characters long. The password should contain at least one uppercase and at least one lowercase letter. The password should have at least one digit. Write a...
Using Python, generate a random password which meets these rules and show five examples of the...
Using Python, generate a random password which meets these rules and show five examples of the random passwords. rules: password contains 6-20 characters, contain at least one lowercase letter, at least one uppercase letter, and at least one digit, must not contain three repeating characters in a row ("...aaa..." is weak, but "...aa...a..." is strong, assuming other conditions are met).
Each user on a computer system has a password, which is seven to nine characters long,...
Each user on a computer system has a password, which is seven to nine characters long, where each character is an uppercase letter or a digit. Each password must contain at least one digit or at least one Uppercase letter. How many possible passwords are there?
A company wants to impose a more secure password system for its employees to use on...
A company wants to impose a more secure password system for its employees to use on the company’s network. The current policy requires a minimum of seven characters. The system under consideration requires a minimum of eight characters. The new system will allow repetition of characters, but not doubling (e.g., the sequence 121 would be acceptable, but not 112). For both password systems, assume the following: Only alphanumeric characters can be used in the passwords, without any spaces or symbols....
A system administration of our school has instituted the following rules when it comes to the...
A system administration of our school has instituted the following rules when it comes to the creation of our school’s email password: (i) A password must be exactly 8 characters long;(ii) A password must begin with an uppercase letter; (iii) The last character of a password must be a digit. The character set from which a password can be created includes numerals (digits), upper and lower case letters. Determine the maximum number of passwords available.
1- A particular automatic sprinkler system has two different types of activation devices for each sprinkler...
1- A particular automatic sprinkler system has two different types of activation devices for each sprinkler head. One type has a reliability of 0.87; that is, the probability that it will activate the sprinkler when it should is 0.87. The other type, which operates independently of the first type, has a reliability of 0.77. If either device is triggered, the sprinkler will activate. Suppose a fire starts near a sprinkler head. a) What is the probability that the sprinkler head...
For this assignment, you need to submit a Python program that gathers the following employee information...
For this assignment, you need to submit a Python program that gathers the following employee information according to the rules provided: Employee ID (this is required, and must be a number that is 7 or less digits long) Employee Name (this is required, and must be comprised of primarily upper and lower case letters. Spaces, the ' and - character are all allowed as well. Employee Email Address (this is required, and must be comprised of primarily of alphanumeric characters....
2) Allowing (or requiring) users to use numerical digits (including 0) and one of 28 “special...
2) Allowing (or requiring) users to use numerical digits (including 0) and one of 28 “special characters” dramatically increases the number of possible passwords. Furthermore, passwords often are case-sensitive, effectively doubling the size of the alphabet by defining 52 distinct letter characters.    Assuming that passwords are case-sensitive and can include numerical digits and special characters, how many possible 6, 8 and 10 character passwords can be created? (8 points) 3) Allowing digits and special characters creates an enormous number...
Data Encryption (Strings and Bitwise Operators) Write a C program that uses bitwise operators (e.g. bitwise...
Data Encryption (Strings and Bitwise Operators) Write a C program that uses bitwise operators (e.g. bitwise XOR) to encrypt/decrypt a message. The program will prompt the user to select one of the following menu options: 1. Enter and encrypt a message 2. View encrypted message 3. Decrypt and view the message (NOTE: password protected) 4. Exit If the user selects option 1, he/she will be prompted to enter a message (a string up to 50 characters long). The program will...
Create a function in MIPS using MARS to determine whether a user input string is a...
Create a function in MIPS using MARS to determine whether a user input string is a palindrome or not. Assume that the function is not part of the same program that is calling it. This means it would not have access to your .data segment in the function, so you need to send and receive information from the function itself. The program should be as simple as possible while still using necessary procedures. Follow the instructions below carefully. Instructions: ●...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT