Good evening, I've been toiling around with restructuring a program which is supposed to register a preexisting input file, which contains four different passwords, and have it pass through the verification process, to see which of those passwords meets all the criteria set by the highlighted parameters. The code stipulates that in order for a password to be considered valid, it should contain a minimum of 6 characters in total, at least 2 lowercase letter, at least 1 uppercase letter, at least 1 numerical digit, and one "special character". The note file that is supposed to be read by the program is referred to as passwdin-1.txt within the main, and should output a note file called passwdout.txt.
def checkpassword(password): numDigits = 0 numUpperCase = 0 numLowerCase = 0 lPsswd = len(pswd) specialcharacters = False for ch in pswd: if ch.isdigit(): numDigits+=1 elif ch.islower(): numLCase += 1 elif ch.isupper(): numUCase += 1 if lPsswd >=6 and numDigits > 0 and numUCase > 0 and numLCase > 0: print("Password Accepted") else: print("Password not accepted") if letter=='$' or letter=='!' or letter=='%': contains_special_character=True if lPsswd < 6 : print("Password has to be atleast 6 characters or more; not accepted") elif numDigits < 1: print("Number of digits within password has to be at least 1;not accepted") elif numLCase == 0: print("Number of lowercase within password has to be at least 2") elif numUCase == 0: print("Number of uppercase has to be at least 1") elif not contains_special_character: print ("The password should have a special character like $ or ! or %") else: print("Password accepted") def main(): input_file = "F:\\passwdin-1.txt" output_file = "F:\\passwdout.txt" output_lines=[] with open(input_file) as input_f: for line in input_f: message=checkPassw0rd(line.rstrip('\n')) print(message) if message=="Password Accepted": output_lines.append(line.rstrip('\n')+" - Password Accepted") else: output_lines.append(line.rstrip('\n')+" - Password is not accepted.") output_lines.append(message) with open(output_file, 'w') as output_f: for line in output_lines: output_f.write(line) output_f.write("\r\n") main()
The expected result would be for the program to undergo the aforementioned process of reviewing a note file containing 4 distinct passwords, and outputting a resuting note file containing the results of the validation process. When a attempt to run the program in the module however, in get an error pertaining to the passwdin-1.txt file not being found within the directory, even though I'm know the file exists on my computer. Assuming this is less of an issue pertaining to my code, and more with how I get python to access the input file, I'd appreciate some guidance on how to do that.
Solution:
Please find below the code and output:
def checkpassword(password): numDigits = 0 numUpperCase = 0 numLowerCase = 0 lPsswd = len(password) specialcharacters = False for ch in password: if ch.isdigit(): numDigits+=1 elif ch.islower(): numLowerCase += 1 elif ch.isupper(): numUpperCase += 1 elif ch=='$' or ch=='!' or ch=='%': specialcharacters=True if lPsswd < 6 : print("Password has to be atleast 6 characters or more; not accepted") elif numDigits < 1: print("Number of digits within password has to be at least 1;not accepted") elif numLowerCase == 0: print("Number of lowercase within password has to be at least 2") elif numUpperCase == 0: print("Number of uppercase has to be at least 1") elif not specialcharacters: print ("The password should have a special character like $ or ! or %") if lPsswd >= 6 and numDigits > 0 and numUpperCase > 0 and numLowerCase > 0 and specialcharacters: return "Password Accepted" else: return "Password not accepted" def main(): input_file = "E:\\pwd.txt" output_file = "E:\\passwdout.txt" output_lines=[] with open(input_file) as input_f: for line in input_f: message=checkpassword(line.rstrip('\n')) print(message) if message=="Password Accepted": output_lines.append(line.rstrip('\n')+" - Password Accepted") else: output_lines.append(line.rstrip('\n')+" - Password is not accepted.") output_lines.append(message) with open(output_file, 'w') as output_f: for line in output_lines: output_f.write(line) output_f.write("\r\n") main()
Input file:
Output file:
Good evening, I've been toiling around with restructuring a program which is supposed to register a...
Please make this Python code execute properly. User needs to create a password with at least one digit, one uppercase, one lowercase, one symbol (see code), and the password has to be atleast 8 characters long. try1me is the example I used, but I couldn't get the program to execute properly. PLEASE INDENT PROPERLY. def policy(password): digit = 0 upper = 0 lower = 0 symbol = 0 length = 0 for i in range(0, len(password)): if password[i].isdigit(): # checks...
Python Programming 4th Edition: Need help writing this program below. I get an error message that says that name is not defined when running the program below. My solution: def main(): filename = "text.txt" contents=f.read() upper_count=0 lower_count=0 digit_count=0 space_count=0 for i in contents: if i.isupper(): upper_count+=1 elif i.islower(): lower_count+=1 elif i.isdigit(): digit_count+=1 elif i.isspace(): space_count+=1 print("Upper case count in the file is",upper_count) print("Lower case count in the file is",lower_count) print("Digit count in the file is",digit_count) print("Space_count in the file is",space_count)...
Write a program that asks the user to enter a password, and then checks it for a few different requirements before approving it as secure and repeating the final password to the user. The program must re-prompt the user until they provide a password that satisfies all of the conditions. It must also tell the user each of the conditions they failed, and how to fix it. If there is more than one thing wrong (e.g., no lowercase, and longer...
Write a program that inputs a string from the user representing a password, and checks its validity. A valid password must contain: -At least 1 lowercase letter (between 'a' and 'z') and 1 uppercase letter (between 'A' and 'Z'). -At least 1 digit (between '0' and '9' and not between 0 and 9). At least 1 special character (hint: use an else to count all the characters that are not letters or digits). -A minimum length 6 characters. -No spaces...
Write a program that first reads in the name of an input file and then reads the input file using the file.readlines() method. The input file contains an unsorted list of number of seasons followed by the corresponding TV show. Your program should put the contents of the input file into a dictionary where the number of seasons are the keys, and a list of TV shows are the values (since multiple shows could have the same number of seasons).Sort...
python program Use the provided shift function to create a caesar cipher program. Your program should have a menu to offer the following options: Read a file as current message Save current message Type in a new message Display current message "Encrypt" message Change the shift value For more details, see the comments in the provided code. NO GLOBAL VARIABLES! Complete the program found in assignment.py. You may not change any provided code. You may only complete the sections labeled:#YOUR...
I have a python project that requires me to make a password saver. The major part of the code is already giving. I am having trouble executing option 2 and 3. Some guidance will be appreciated. Below is the code giving to me. import csv import sys #The password list - We start with it populated for testing purposes passwords = [["yahoo","XqffoZeo"],["google","CoIushujSetu"]] #The password file name to store the passwords to passwordFileName = "samplePasswordFile" #The encryption key for the caesar...
Write a python program write a function numDigits(num) which counts the digits in int num. Answer code is given in the Answer tab (and starting code), which converts num to a str, then uses the len() function to count and return the number of digits. Note that this does NOT work correctly for num < 0. (Try it and see.) Fix this in two different ways, by creating new functions numDigits2(num) and numDigits3(num) that each return the correct number of...
JAVA PROBLEM! PLEASE DO IT ASAP!! REALLY URGENT! PLEASE DO NOT POST INCOMPLETE OR INCORRECT CODE Below is the program -- fill the code as per the instructions commented: //---------------------------------------------------------------------------------------------------------------------------------------------------------------// /* The idea of this HW is as follows : A password must meet special requirements, for instance , it has to be of specific length, contains at least 2 capital letters , 2 lowercase letters, 2 symbols and 2 digits. A customer is hiring you to create a class...