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 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:...
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...
Write a program called Assignment3 (saved in a file Assignment3 .java) that asks a user to...
Write a program called Assignment3 (saved in a file Assignment3 .java) that asks a user to enter two strings. First, the program prompts: Please enter a string. The program should read in the string, and prompts: Please enter another string. The program reads in two strings and it prints a menu to the user. The program asks for user to enter an option and performs one of the following: Here are the options on the menu: Option a: checks if...
In C write a program that asks the user for the dimensions of 3 sides of...
In C write a program that asks the user for the dimensions of 3 sides of a triangle. Each side dimension must be between 1.00 and 100.00 including 1.00 and 100.00. If the side dimensions indeed can make a valid triangle then the program should use these values to determine the perimeter and the area of the valid triangle 1. Must use programmer define functions 2. Your program must have at least 4 functions, main and the following 3 functions:...
Using C++ Write a program to ask user to enter a password and validity the password....
Using C++ Write a program to ask user to enter a password and validity the password. The password should be 8 – 20 characters long (8 is included and 20 is included), it should contain at least one uppercase letter and one lower case letter. The password should contain at least one digit, and at least one symbol other than alphabets or numbers. Most importantly, the password may not contain any white space. Functions: You will need at least the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT