This is my python code. It should write failed password to a text, producing a text.write output
Fantastic news! We've Found the answer you've been seeking!
Question:
This is my python code. It should write failed password to a text, producing a text.write output of
date time, password <6 date time, password >10
Why can I not get this code to write to file? everything seems correct but it does not log the failed password as requested
Python Code
from datetime import datetime # import the current date and time def main(): print("PasswordChecker2 program developed by: name here") # constants for password length MIN_PASSWORD_LENGTH = 6 MAX_PASSWORD_LENGTH = 10 # "a" here means add to file, if file doesn't exist it creates the file automatically f = open("password_log.txt", "a") date_s = (datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')) password = input("Enter the password: ") password_length = len(password) while password_length < MIN_PASSWORD_LENGTH or password_length > MAX_PASSWORD_LENGTH: print("Password length must be between 6 and 10, please re-enter password") password = input("Enter the password: ") if password_length < MIN_PASSWORD_LENGTH: f.write(f")date_s), Password <6 ") elif password_length > MAX_PASSWORD_LENGTH: f.write(f")(date_s), Password >10 ") # checking if password has only letters if password.isalpha(): print("Password has ", password_length, " characters and it is weak - contains only letters") # checking if password has only numbers elif password.isnumeric(): print("Password has ", password_length, " characters and it is weak - contains only numbers") # reaching here, password will have both letters and numbers of proper length else: print("Password has ", password_length, " characters and is strong") f.close() # this is where it closes and writes to the file main() # end of main function
Related Book For
Posted Date: