Question

In: Computer Science

[10, 3, 15, 18] 4. Password Checker Write a fuction called passwordChecker() that asks the user...

[10, 3, 15, 18]


4.


Password Checker


Write a fuction called


passwordChecker()


that asks the user to input a string and


checks if the string can be used as a password. Loop until the user inputs an


appropriate password. A password must satisfy the following conditions:


(a) Must contain at least 12 characters


(b) Must contain one special symbol from string.punctuation [HINTS: use the


string


module; use the keyword


in


]


(c) Must contain at least one lower-case letter


(d)


Solutions

Expert Solution

Hi,

Hope you are doing fine. I have code the above question in python. All the conditions in the program have been met and the clear explanation and logic has been explained using the comments which have been highlighted in bold.

Program:

#importing string library for string.punctuation
import string

#function passwordChecker
def passwordChecker():
#The loop is continuosly executed until we use a break statement
while True:
#length_flag is used to indicate if the length is greater than 12 characters
length_flag=0
#special_flag is used to see if the string contains atleast one special character
special_flag=0
#count is used to count the number of lower case characters
count=0
#taking input from user
pwd=input('Enter the password: ')
  
#if length of string > 12
if len(pwd)>=12:
#flag is set to 1
length_flag=1
  
#iterating each character of string
for x in range(0,len(pwd)):
#if he character is present in string.punctuation
if pwd[x] in string.punctuation:
#flag is set to 1
special_flag=1
#if the character is a lower case, then we increase the count
if pwd[x].islower():
count=count+1
  
#if both flags are set to 1 and count>0 then we print that it is a valid password and break out of the loop
if length_flag==1 and special_flag==1 and count>0:
print("Valid password!")
break
#else
else:
print("Invalid password")
#if the length is less than 12
if length_flag!=1:
print("The password must contain atleast 12 characters")
#if there are no special characters
if special_flag!=1:
print("The password must contain atleast one special character")
#if there are no lower case characters
if count==0:
print("The password must contain at least one lower-case letter")
print("Please re-enter\n")
#the loop iterates again asking for input

#calling function from main to check execution
passwordChecker()

Executable code snippet from jupyter notebook:

Output:


Related Solutions

Write a pro-active password checker that checks to make sure that a user entered password meets...
Write a pro-active password checker that checks to make sure that a user entered password meets certain requirements. You must implement a simple program that prompts the user for two String values, a password and the same password again for confirmation. For the purposes of this lab, a legal password must have all of the following properties: ▪ Length of at least 8 characters ▪ Starts with a lower case letter ▪ Ends with a numerical digit ▪ Has one...
In PYTHON: Write a program that asks for a password from a user and checks if...
In PYTHON: Write a program that asks for a password from a user and checks if it satisfies the conditions: Contains at least one lowercase letter (a-z). Contains at least one uppercase letter (A-Z). Contains at least one digit (0-9). Minimum length 6 characters. Contains no spaces. If the password is valid, then the program prints “password accepted”. Otherwise, it keeps asking for more passwords from the user until a valid password is obtained. Hint: You might like to check...
In.java Write a program that repeatedly asks the user to enter their password until they enter...
In.java Write a program that repeatedly asks the user to enter their password until they enter the correct one. However, after 5 failed attempts, the program "locks out" the user. We will show that with an error message. Assume the password is HOC2141 (case sensitive). Note that there is a special case that is not shown below. To identify it, think of all possible scenarios of input for this program. ----------- Sample run 1: Enter your password: Blake Wrong Enter...
Write Python code that asks the user for a password from the console and continues asking...
Write Python code that asks the user for a password from the console and continues asking for a password until the user enters a password that has greater than 10 characters. (language python)
C# Create an application that asks the user to enter their new password. The password must...
C# Create an application that asks the user to enter their new password. The password must be at least 6 characters long. Develop a custom exception handling case that checks for the password length. (hint: use " .Length " built-in method). If the new password is less than 6 characters long the custom exception should output an error message.
In a file called LengthSum.java, write a program that: - Asks the user to enter a...
In a file called LengthSum.java, write a program that: - Asks the user to enter a string. - Asks the user to enter a second string. - Prints out the length of the first string, the length of the second string, and the sum of the two lengths, using EXACTLY the same format as shown below. For example: if the user enters strings "UT" and "Arlington", your program output should look EXACTLY like this: Please enter a string: UT Please...
Create a Java application called ValidatePassword to validate a user’s password. Write a program that asks...
Create a Java application called ValidatePassword to validate a user’s password. Write a program that asks for a password, then asks again to confirm it. If the passwords don’t match or the rules are not fulfilled, prompt again. Your program should include a method that checks whether a password is valid. From that method, call a different method to validate the uppercase, lowercase, and digit requirements for a valid password. Your program should contain at least four methods in addition...
In a file called LengthSum.java, write a program that: Asks the user to enter a string....
In a file called LengthSum.java, write a program that: Asks the user to enter a string. Asks the user to enter a second string. Prints out the length of the first string, the length of the second string, and the sum of the two lengths, using EXACTLY the same format as shown below. For example: if the user enters strings "UT" and "Arlington", your program output should look EXACTLY like this: Please enter a string: UT Please enter a second...
In a file called Conversions.java, write a program that: Asks the user to enter a double...
In a file called Conversions.java, write a program that: Asks the user to enter a double number. Stores that number into a variable called z. Casts variable z into an integer, and stores the result into a variable called z1. Creates a variable z2, and sets it equal to the integer closest to z. Creates a variable z3, and sets it equal to the floor of z. Creates a variable z4, and sets it equal to the ceiling of z....
In a file called FourCapitalizations.java, write a program that: Asks the user to enter a string....
In a file called FourCapitalizations.java, write a program that: Asks the user to enter a string. Prints out four different versions of that string: The original version of the string. The upper-case version of the string. The lower-case version of the string. A version where the character at position 0 capitalized, and all other characters in lower case. For example: if the user enters string "gaNDalF12 !! AB3w", your program output should look EXACTLY like this: Please enter a string:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT