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...
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...
Write C++ void function called averageTemperature() that asks the user to enter integers with a sentinel...
Write C++ void function called averageTemperature() that asks the user to enter integers with a sentinel value of -999 to stop entering numbers. Then average the numbers and print the average. You will need an int acculumator for the temperatures and an int acculumator for the number of temperatures entered. Use the accumulators to calculate the average which will need to be a decimal number. Call the function from the main() function.
Write a C program that asks the user to guess a number between 1 and 15(1...
Write a C program that asks the user to guess a number between 1 and 15(1 and 15 are included). The user is given three trials. This is what I have so far. /* Nick Chioma COP 3223 - HW_2 */ #include <iostream> #include <time.h> // needed for time function #include <stdlib.h> // needed for srand, rand functions int main () {       int numbertoguess, num, correct, attempts;       srand(time(NULL)); //this initializes the random seed, making a new...
[4 marks] Write a Python program for a “Deliver-Eat!” app that asks the user for their...
[4 marks] Write a Python program for a “Deliver-Eat!” app that asks the user for their tip amount. If the user tips less than $5 they should receive a 1-star rating. If the user tips $5 or more they should receive a 5-star rating. Your program should match the output below. User input is in red. >>> How much would you like to tip? $4.50 >>> Here is your rating! * >>> How much would you like to tip? $7.20...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT