Question

In: Computer Science

Write a program that validates passwords based on the following requirements: • must be at least...

Write a program that validates passwords based on the following requirements:
• must be at least 8 characters in length
• must include at least 1 alphabet character
• must include at least 1 number

The program should implement the password checker using a function name validate_password,
which takes two strings as input and returns one of the following:
• 0 if the passwords match and fulfill all requirements
• 1 if the passwords are not the same length
• 2 if the a number is not found
• 3 if an alphabet character is not found

In main, test your function validate_password by creating 4 sets of passwords and which match one of the conditions listed above and printing the result.

Need it in 10 minutes, please.

Solutions

Expert Solution

Code written in python:

def validate_password(password1, password2):
    if len(password1) != len(password2) and len(password1) >= 8: # checks the length of two passwords
        return 1

    elif password1.isalpha(): #checks if the password is not only alphabets that does it contain number or not
        return 2

    elif password1.isnumeric(): #checks if the password is not only numeric that is does it contain alphabet or not
        return 3

    else:    #for correct password
        return 0

if __name__ == '__main__':
    res = validate_password("qwer45678", "qwer45678") #perfect password
    print(res)
    res = validate_password("qwer4567", "qwer45678") # difference in length
    print(res)
    res = validate_password("qwertyuv", "qwertyuv") # only alphabets
    print(res)
    res = validate_password("12345678", "12345678") # only numbers
    print(res)

Output:

len() helps in verifying length of both passwords

isalpha() helps in checking that the number password contains only alphabet i.e it will be true when the password contains only alphabet and false if the password is alphanumeric

isnumeric() helps in checking that the number password contains only numbers i.e it will be true when the password contains only numbers and false if the password is alphanumeric

So in both isalpha() and isnumeric() if value is True then we return 2 and 3 and in the end else we will return 0


Related Solutions

Write a program that validates passwords based on the following requirements: • must be at least...
Write a program that validates passwords based on the following requirements: • must be at least 8 characters in length • must include at least 1 alphabet character • must include at least 1 number The program should implement the password checker using a function name validate_password, which takes two strings as input and returns one of the following: • 0 if the passwords match and fulfill all requirements • 1 if the passwords are not the same length •...
c++ Develop a program that validates a password entered by a user. The password must meet...
c++ Develop a program that validates a password entered by a user. The password must meet the following criteria: Be at least six characters long. Contain at least one uppercase and at least one lowercase letter. Have at least one digit. Write a program that asks for a password and then verifies that it meets the stated criteria. If it does not, the program should display a message telling the user why and ask for another password. The program should...
Program Requirements: Write a C++ program according to the following requirements: 1.   Open the data file...
Program Requirements: Write a C++ program according to the following requirements: 1.   Open the data file Electricity.txt and read each column into an array (8 arrays total). 2.   Also create 2 arrays for the following: Total Fossil Fuel Energy (sum of all fossil fuels) Total Renewable Energy (sum of all renewable sources) Electricity.txt: Net generation United States all sectors monthly https://www.eia.gov/electricity/data/browser/ Source: U.S. Energy Information Administration All values in thousands of megawatthours Year   all fuels   coal       natural gas   nuclear  ...
Write a program which: Prompts the user for a positive integer >= 0 Validates the user...
Write a program which: Prompts the user for a positive integer >= 0 Validates the user input to ensure it is a positive integer >= 0 Allocate (dynamically) an array big enough for the data. Load the array with random numbers ranging in value from1 to 100 Display the elements of the array (unsorted) Display the elements of the array (sorted) Display the average Display the median Display the mode, if none, display appropriate message RESTRICTIONS No global variables No...
To write a C++ program for following scenario and display requirements: Scenario-based Problem: AIG Insurance wants...
To write a C++ program for following scenario and display requirements: Scenario-based Problem: AIG Insurance wants to create an insurance management system for their clients. The insurance management system will compute the required payments from the clients. The commission of the agent shall also be computed which depends on the amount of insurance type. Insurance Type Amount of Insurance type Agent Commission Life 2500 12.5% of amount Health 1500 10.5% of amount Other inputs 0 0 Computation of monthly payments...
Program must be in C++! Write a program which: Write a program which uses the following...
Program must be in C++! Write a program which: Write a program which uses the following arrays: empID: An array of 7 integers to hold employee identification numbers. The array should be initialized with the following values: 1, 2, 3, 4, 5, 6, 7. Hours: an array of seven integers to hold the number of hours worked by each employee. payRate: an array of seven doubles to hold each employee’s hourly pay rate. Wages: an array of seven doubles to...
The following information describes the requirements for your response: It must be at least three paragraphs...
The following information describes the requirements for your response: It must be at least three paragraphs long (more is usually better), grammatically correct, and demonstrate that you understand and can apply the concepts covered in the second competency module. When writing your response, follow the steps listed below in the order that they appear. Step One: Begin by describing the process for calculating price elasticity of demand. Then, using fictitious numbers, calculate the price elasticity of demand for donuts at...
Write any java programming to meet the following requirements. Your project must meet the following requirements:...
Write any java programming to meet the following requirements. Your project must meet the following requirements: 1. Specify input specification      Design input 2. Specify Output Specification     Design Output 3. The class must include set methods and get methods ( with or without parameters both) 4. Must include Array structure 5. Must include Input or Output Files or both 6. Demonstrate your knowledge of an Applet
Write a program in c++, with at least four functions, including main, which must do the...
Write a program in c++, with at least four functions, including main, which must do the following: Ask user whether they want to encode or decode a message – if no, then terminate Take the input string from the user, store it in dynamic memory (use new) As appropriate, encode or decode the message using Rot13. Output the encoded/decoded message Delete the input string from dynamic memory (use delete) Input will be a string of no more than 25 characters....
[JAVA] You will write a program to validate passwords for users, making sure they meet the...
[JAVA] You will write a program to validate passwords for users, making sure they meet the following criteria: Rules: Passwords must be at least 8 characters long Passwords can only contain alpha numeric characters (no spaces or special characters) Passwords must contain at least 1 uppercase character Passwords must contain at least 1 lowercase character Passwords must contain at least 1 numeric character (0-9) Passwords cannot contain the word “password” A password that does not meet all of these rules...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT