Advertisement
Guest User

Coursework code

a guest
Dec 14th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.65 KB | None | 0 0
  1. global usernameInput
  2. global passwordInput
  3. global username1
  4. global password
  5. import random
  6. import time
  7.  
  8.  
  9. def title():
  10.  
  11.     print("  ______ _____ _____  _____  ______  ___  _____  _____   ")
  12.     print("  |  _  \_   _/  __ \|  ___| | ___ \/ _ \/  __ \|  ___|  ")
  13.     print("  | | | | | | | /  \/| |__   | |_/ / /_\ \ /  \/| |__    ")
  14.     print("  | | | | | | | |    |  __|  |    /|  _  | |    |  __|   ")
  15.     print("  | |/ / _| |_| \__/\| |___  | |\ \| | | | \__/\| |___   ")
  16.     print("  |___/  \___/ \____/\____/  \_| \_\_| |_/\____/\____/   ")
  17.                                                    
  18.  
  19.     print("---------------------------------------------------------------------------------------------------------------")
  20.     choice = input("Type Start to start")
  21.     if choice == "Start":
  22. ##takes user to the login screen
  23.         loginUser1()
  24.     else:
  25.         title()
  26.  
  27.  
  28.  
  29. def loginUser1():
  30. ##login for first user
  31.     global usernameInput
  32.     global username1
  33.    
  34.     print("Please log in using your correct username")
  35.     print("-----------------------------------------")
  36.     usernameInput = input("Username:") ##enter username
  37.     usernamedb = open("usernamedb.txt","r") ##open file and reaf usernames
  38.     name = usernamedb.read()
  39.     username1 = name
  40.     if username1 in name: ##checking to see if the username entered matches a username in  the file
  41.         usernamedb.close() ##closes  file
  42.         loginPass1()
  43.     else:
  44.         usernamedb.close()
  45.         time.sleep(3) ##sets a delay of 3 seconds
  46.         loginUser1()
  47.        
  48.  
  49. def loginPass1():
  50.     global passwordInput
  51.     global password
  52.  
  53.     print("Please log in using the correct password")
  54.     print("----------------------------------------")
  55.     passwordInput = input("Password:") ##enter password
  56.     passworddb = open("passworddb.txt","r") ##open file
  57.     passphrase = passworddb.read()
  58.     password = passphrase
  59.     if password in passphrase: ##checking to see if the username entered matches a username in  the file
  60.         passworddb.close() ##close the file
  61.         loginUser2()
  62.     else:
  63.         passworddb.close()
  64.         time.sleep(3) ##sets a delay of 3 seconds
  65.         loginUser1()
  66.  
  67.  
  68. def loginUser2():
  69.     global usernameInput
  70.     global username1
  71.    
  72.     print("Please log in using your correct username")
  73.     print("-----------------------------------------")
  74.     usernameInput = input("Username:") ##emter second username
  75.     usernamedb = open("usernamedb.txt","r") ##open file
  76.     name = usernamedb.read()
  77.     username2 = name
  78.     if username2 == username1: ##checks if username 2 is the sam eas username 1
  79.         usernamedb.close() ##closes file
  80.         time.sleep(3) ##sets a delay of 3 seconds
  81.         loginUser2()
  82.     elif username2 in name: ##checking to see if the second username entered matches a username in  the file
  83.         usernamedb.close()
  84.         loginPass2()
  85.     else:
  86.         usernamedb.close()
  87.         time.sleep(3)
  88.         loginUser2()
  89.  
  90.  
  91. def loginPass2():
  92.     global passwordInput
  93.     global password
  94.  
  95.     print("Please log in using the correct password")
  96.     print("----------------------------------------")
  97.     passwordInput = input("Password:") ##enter password
  98.     passworddb = open("passworddb.txt","r") ## open file
  99.     passphrase = passworddb.read()
  100.     password = passphrase
  101.     if password in passphrase: ##checking to see if the username entered matches a username in  the file
  102.         passworddb.close() ##close the file
  103.         game()
  104.     else:
  105.         passworddb.close()
  106.         time.sleep(3) ##sets a delay of 3 seconds
  107.         loginUser2()        
  108.  
  109.  
  110.  
  111. def game():
  112.     print("ay")
  113.  
  114.  
  115.  
  116. title()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement