Python Forum
Password Checker Assignment
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Password Checker Assignment
#1
Hi all I'm new to coding and am currently doing a assignment called Password Checker.
It has been split into 4 parts and I have passed the first 2 and am stuck halfwayish on the third part.

Basically I have to create A program that is required to input and validate a password to ensure it contains the minimum number of characters (6) and a maximum of 10 characters.
For every unsuccessful attempt, the program will record an entry in a password log file that will include the date/time (updated to the nearest microsecond) and the reason why the password in invalid either “password < 6” or “password >10”. The file will not store any passwords.
Once validated, the program will output the length of the password and determine if the password is weak or if the password is strong.
The program will then output all the contents of the password log file to the screen.
My code so far:

def main():

import datetime

print("PasswordChecker2 Program developed by Matthew Costello")
#constants that need to be used
MIN_LENGTH = 6
MAX_LENGTH = 10
PASSWORD_LOG_FILE = "password_log_matthew_costello.txt"

#password input
password = input("Please enter your password for checking: ")

# This part of the code uses len(password) to calculate a passwords length in characters and a while loop to validate
# whether the password meets the min and max parameters and keeps asking for input until satisfied.
while len(password) < MIN_LENGTH or len(password) > MAX_LENGTH:
print("Invalid")
password = input("Please enter your password for checking: ")

# This will opens a .txt file and write the current date and time and a message to why password was invalid.
# Will not store password.
error_log = str(datetime.datetime.now())
output_file = open(PASSWORD_LOG_FILE, "a+")
output_file.write(error_log)
output_file.write("\n")
output_file.close()

# This second part is to determine if a password is all numbers, all letters or a combination of both.
# Outcome of weak or strong.
if password.isnumeric() is True:
comment = "password is weak - contains only numbers."
elif password.isalpha() is True:
comment = "password is weak - contains only letters."
else:
comment = "password is strong."

print("Your password is {:} characters long".format(len(password)))
print("Your {:s}".format(comment))

input_file = open(PASSWORD_LOG_FILE, "r")

for line in input_file:
print(line, end='')

input_file.close()


main()

As you can see I have been able to open text file write to it the datetime and the have contents displayed on screen. But I am unsure how to have the error message displayed as well on same line as date time.
I have tried IF statements, WHILE statements and changing flow of code. I can never seem to get it to work.
Lastly the only other thing I cant get to work is that if an invalid code is entered more than once in a row it only records the most recent attempt to the file now all failed attempts.

Cheers for any help anyone can give.
Reply
#2
You should put your code in python tags, to show indentation.
I'm not sure what the original text of the assignment is, but I'm
suggesting you question your validation. if it's not all numeric and not all alphanumetic,
you conclude it must me a mix and therefore a valid pw.
pw = 'abc,123' is neither but might not be not a valid pw either.
Paul
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Password Saver Assignment sshellzr21 2 6,104 May-02-2020, 01:34 AM
Last Post: sshellzr21
  Palindrome checker case sensive edwdas 3 2,585 Nov-07-2019, 05:57 PM
Last Post: nilamo
  "Travis" guest list name checker (Ziyad Yehia Udemy course) Drone4four 8 3,906 Aug-24-2019, 03:46 PM
Last Post: jefsummers
  Syntax checker BZA 4 3,142 May-16-2019, 06:40 PM
Last Post: BZA
  Spell Checker Liquid_Ocelot 1 3,154 May-07-2017, 11:28 AM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020