Advertisement
Guest User

Untitled

a guest
Mar 15th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. import time
  2. import os
  3. import yaml
  4.  
  5. def loading_pass(): # Used for loading in username and password automatically
  6. with open("Output.txt", "r") as f:
  7. txt = f.read() # Read text file
  8.  
  9. global dic
  10. dic = yaml.load(txt) # Convert string into dictionary
  11.  
  12. confirmation = input("Would you like to automatically login? Y/N ")
  13. if confirmation.lower() == "y":
  14. pass
  15.  
  16. elif confirmation.lower() == "n":
  17. setup()
  18.  
  19.  
  20. else:
  21. print("Invalid answer")
  22. loading_pass()
  23.  
  24. global name
  25. global password
  26. for name, password in dic.items(): # Loads username and password from hashed txt file
  27.  
  28. print("\nWelcome " + str(name) + "." + " You have sucessfully logged in.")
  29.  
  30.  
  31.  
  32.  
  33. def setup(): # Function for setting up username & pass
  34. stat_info = os.stat("Output.txt") # Read the size of the file
  35. if stat_info.st_size > 0:
  36. loading_pass() # Call loading_pass function
  37. return
  38.  
  39.  
  40. global username # Initiate global username
  41. username = input("\nPlease enter a username ")
  42.  
  43. global passw # Initiate global password
  44. passw = input("Enter a password ")
  45.  
  46.  
  47. user_info = {username: hash(passw)} # Initiate dictionary for saving password
  48. print(user_info)
  49.  
  50. confirmation = input("\nAre you sure? Once the username and password have been created you cannot reset it. Y/N ") # Asks user for confirmation
  51. remember_pass = input("\n Would you like to remember your password? Y/N ")
  52.  
  53. if confirmation.lower() == "y": # Saves pass
  54. print("\nUsername and password created succesfully")
  55.  
  56. elif confirmation.lower() == "n": # Aborts setup
  57. print("\nAccount creation aborted")
  58. username = None
  59. passw = None
  60. user_info = {None:None}
  61. setup()
  62.  
  63. else:
  64. print("\nInvalid answer") # Invalid answer
  65. setup()
  66.  
  67. if remember_pass.lower() == "y": # Writing to text file
  68. txtfile = open("Output.txt", "w+")
  69. txtfile.write(str(user_info))
  70. txtfile.close()
  71.  
  72. elif remember_pass.lower() == "n":
  73. user_info = None
  74.  
  75.  
  76. else:
  77. print("Invalid answer")
  78. setup()
  79.  
  80. def login(): # Login function
  81.  
  82. for attempt in range(2,-1,-1):
  83. username_pass = input("\nEnter your username ") # Enter the username they set
  84. login_pass = input("Enter your password ") # Enter the password they set
  85.  
  86. if username_pass == username:
  87. pass
  88. else:
  89. print("\nWrong username!")
  90.  
  91. 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
  92. print("\nWelcome " + str(username) + " you are now logged in")
  93. break
  94.  
  95. else: # If wrong password then initiate retry function
  96. print("\nWrong password!")
  97. print("%s Retries left!" %attempt)
  98.  
  99. if attempt == 0: # Reaches 0 app will close
  100. print("Maximum retries reached! Account locked")
  101. break
  102.  
  103. if __name__ == "__main__":
  104. setup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement