#Python Challenge
#Create a login script for 5 users that checks their username and password is correct.
#Once they are logged in they should be greeted and given today’s date and time.

from datetime import datetime
import time
import getpass

##########################################################
def login_pass(username):
  now = datetime.now()
  current_time = now.strftime("%H:%M:%S")
  print ("Welcome, " + str(username) + " you successfully logged in at " + current_time)

##########################################################

users = [["Matthew","123456"],["Mark","123456"],["Luke","123456"],["John","123456"],["Dave","123456"]]
flag = True #used to control login loop
attempts = 0 #used to track number of login attempts for security timeout

while flag == True: #keeps user in loop until they enter correct login details
  username = input("Please enter your user name: ") #collects username from user
  #santitise input cgi.escape
  password = getpass.getpass("Please enter your password: ") #collects password from user
  #sanitiseinput
  attempts = attempts + 1 #increments login attempts

  if attempts <5: #attempts login if lesson than 5
    for i in range (0,len(users)):
      if username.lower() == users[i][0].lower() and password == users[i][1]:
        flag = False
        login_pass(username)
    print("Login Fail")
  else:
    print("5 failed login attempts, security timeout for 5 seconds to prevent Brute-Force attack.")
    time.sleep(5)
    attempts = 0








