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

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:...
In a file called NumbersToMonths.java, write a program that: Asks the user to specify a month...
In a file called NumbersToMonths.java, write a program that: Asks the user to specify a month as an integer between 1 and 12. It is OK for your program to crash when the user does not enter a valid integer. Prints out the name of the corresponding month. Prints out "This number does not correspond to a month." if the integer is less than 1 or greater than 12. For example: if the user enters 1, your program output should...
In a file called DivisibilityTests.java, write a program that: Asks the user to enter an integer....
In a file called DivisibilityTests.java, write a program that: Asks the user to enter an integer. It is OK for your program to crash when the user does not enter a valid integer. If the integer is less than 0, the program prints: "The number is negative." If the integer is divisible by 2 and by 3, the program prints: "The number is even and divisible by 3." If the integer is divisible by 2 but not by 3, the...
3. Write the statements to: • create a user named FooBar with a password of “candybar”...
3. Write the statements to: • create a user named FooBar with a password of “candybar” • assign the payments role created in the previous question to FooBar • assign the create session privilege to FooBar • Show the statements to connect to FooBar 4. For this question, I only need the query statement and not the results. Write the queries that use the user_sys_privs, user_tab_privs, user_role_privs, role_sys_privs and role_tab_privs objects to view the user and role privileges that are...
use python to solve Write a function called word_chain that repeatedly asks the user for a...
use python to solve Write a function called word_chain that repeatedly asks the user for a word until either (1) the user has entered ten words, or (2) the user types nothing and presses enter. Each time the user enters an actual word, your program should print all the words entered so far, in one long chain. For example, if the user just typed "orange", and the user has already entered "apple" and "banana", your program should print "applebananaorange" before...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT