Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import os
- import yaml
- def loading_pass(): # Used for loading in username and password automatically
- with open("Output.txt", "r") as f:
- txt = f.read() # Read text file
- global dic
- dic = yaml.load(txt) # Convert string into dictionary
- confirmation = input("Would you like to automatically login? Y/N ")
- if confirmation.lower() == "y":
- pass
- elif confirmation.lower() == "n":
- setup()
- else:
- print("Invalid answer")
- loading_pass()
- global name
- global password
- for name, password in dic.items(): # Loads username and password from hashed txt file
- print("\nWelcome " + str(name) + "." + " You have sucessfully logged in.")
- def setup(): # Function for setting up username & pass
- stat_info = os.stat("Output.txt") # Read the size of the file
- if stat_info.st_size > 0:
- loading_pass() # Call loading_pass function
- return
- global username # Initiate global username
- username = input("\nPlease enter a username ")
- global passw # Initiate global password
- passw = input("Enter a password ")
- user_info = {username: hash(passw)} # Initiate dictionary for saving password
- print(user_info)
- confirmation = input("\nAre you sure? Once the username and password have been created you cannot reset it. Y/N ") # Asks user for confirmation
- remember_pass = input("\n Would you like to remember your password? Y/N ")
- if confirmation.lower() == "y": # Saves pass
- print("\nUsername and password created succesfully")
- elif confirmation.lower() == "n": # Aborts setup
- print("\nAccount creation aborted")
- username = None
- passw = None
- user_info = {None:None}
- setup()
- else:
- print("\nInvalid answer") # Invalid answer
- setup()
- if remember_pass.lower() == "y": # Writing to text file
- txtfile = open("Output.txt", "w+")
- txtfile.write(str(user_info))
- txtfile.close()
- elif remember_pass.lower() == "n":
- user_info = None
- else:
- print("Invalid answer")
- setup()
- def login(): # Login function
- for attempt in range(2,-1,-1):
- username_pass = input("\nEnter your username ") # Enter the username they set
- login_pass = input("Enter your password ") # Enter the password they set
- if username_pass == username:
- pass
- else:
- print("\nWrong username!")
- if hash(passw) == hash(login_pass) and username_pass == username or username_pass == name and hash(login_pass) == password: # Will log in if pass is correct
- print("\nWelcome " + str(username) + " you are now logged in")
- break
- else: # If wrong password then initiate retry function
- print("\nWrong password!")
- print("%s Retries left!" %attempt)
- if attempt == 0: # Reaches 0 app will close
- print("Maximum retries reached! Account locked")
- break
- if __name__ == "__main__":
- setup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement