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)...
Please can I have a UML Class diagram for the Python program below: def main(): print() print("Welcome to Caesar Encryption and Viginere Decryption Cipher") print() print("Please select an option") option = "c" while option == "c": hello = input('Choose Caesar Cipher encrypt 1:\n' 'Choose Viginere Cipher Decrypt 2:\n') message = input('Enter a message: ') password = input('Enter a password: ') if hello == '1': viginere_cipher(message, password) elif hello == '2': viginere_cipher_decrypt(message, password) print() print("Choose an option") option = input('Enter c...
Password Validation Write a program called PasswordValidationYourLastName that validates a new password, following these guidelines: Must be at least 8 characters Must have at least 1 uppercase letter Must have at least 1 lowercase letter Must have at least 1 digit Write a program that asks for a password, and then asks again to confirm it (you can use the scanner or JOptionPane). Pass those two Strings to a method called validatePassword( ). Your validatePassword( ) should return a boolean...
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...
Part 1: Is this Crazy Password Valid? A good password (in this strange system) should have the following properties: Rule 1: The password should be between 4 and 25 characters inclusive, starting with a letter. Rule 2. The password should not be contained in a list (selected by the user) that contains passwords commonly used by many people thus making these passwords easy to guess. Comparisons with passwords from the list of common passwords should be case insensitive. For example,...
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...