Question: modify this code: All variables and constants need to be defined under this function and no variables/constants are to be used outside of main(). import
modify this code:
All variables and constants need to be defined under this function and no variables/constants are to be used outside of main().
import datetime
# min max length
MIN_PASSWORD_LENGTH = 6
MAX_PASSWORD_LENGTH = 10
# loop continue untill get correct password
while 1:
#input
pasword = input('Enter Password: ')
# password length
print('Password length:',len(pasword))
#check length
if len(pasword) >= MIN_PASSWORD_LENGTH and len(pasword) <= MAX_PASSWORD_LENGTH :
# count letter and digits
letter_count = 0
digit_count = 0
for i in pasword:# i holds each character in String s for every iteration of loop
if i.isalpha():
letter_count+=1# Increment Count by 1
if i.isdigit():
digit_count+=1
#status of password
if digit_count==0:
print(f'Enter {pasword} - stating password is weak - only contain letters')
elif letter_count==0:
print(f'Enter {pasword} - stating password is weak - only contain numbers')
else:
print(f'Enter {pasword} - stating the password is strong.')
break
# if not break then mean password not range
# geting date and time
dt=datetime.datetime.today()
# printing date and time
print('Date and Time:',dt)
#file input
PASSWORD_LOG_FILE = "password_log_sam_bloggs.txt"
with open(PASSWORD_LOG_FILE, "a") as file:
if len(pasword) < 6:
data=str(dt)+', pasword < 6 '
file.write(data)
elif len(pasword) > 10:
data=str(dt)+', pasword > 10 '
file.write(data)
print('Invalid!')
print('Password length is not range, Retry ')
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
