Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
2.2 kB
1
Indexable
Never
import datetime

# main function

def main():

   # min max length

   MIN_PASSWORD_LENGTH = 6

   MAX_PASSWORD_LENGTH = 10

 

   # loop continue until get correct password

   while 1:

       # input

       password = input('Enter Password: ')

 

       # password length

       print('Password length:', len(password))

 

       # check length

       if len(password) >= MIN_PASSWORD_LENGTH and len(password) <= MAX_PASSWORD_LENGTH:

           # count letter and digits

           letter_count = 0

           digit_count = 0

           for i in password: # 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 {password} - stating password is weak - only contain letters')

 

           elif letter_count == 0:

               print(f'Enter {password} - stating password is weak - only contain numbers')

 

           else:

               print(f'Enter {password} - 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_joe_bloggs.txt"

 

       with open(PASSWORD_LOG_FILE, "a") as file:

           if len(password) < 6:

               data = str(dt) + ', password < 6\n'

               file.write(data)

           elif len(password) > 10:

               data = str(dt) + ', password > 10\n'

               file.write(data)

 

       print('Invalid!')

       print('Password length is not range, Retry\n')
   print()

   # read the saved log file and then use a for loop to print the logs

   for line in open("password_log_joe_bloggs.txt","r").readlines():
      print(line,end='')


 
# main function call

main()