Guest User

Untitled

a guest
Nov 15th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. def existingUser():
  2. for i in range(5):
  3. existingUsername = input("What is your user name?")
  4. if existingUsername in open('logins.txt').read():
  5. with open("logins.txt", "r") as myFile:
  6. for num, line in enumerate(myFile, 1):
  7. if existingUsername in line:
  8. passwordLine = num + 1
  9. passwordAttempt = input("What is your password?")
  10. loginsList=myFile.readlines()
  11. passwordText = loginsList[passwordLine]
  12. if passwordText == passwordAttempt:
  13. print("That is correct")
  14. quizSelection()
  15. break
  16. else:
  17. print("That doesn't seem to match. Please try again")
  18.  
  19. def existingUser(max_tries=3):
  20. with open('logins.txt') as fp:
  21. lines = [line.strip() for line in fp.readlines()]
  22. logins = dict(zip(lines[::2], lines[1::2]))
  23.  
  24. for n in range(max_tries):
  25. username = input("What is your user name? ")
  26. password = input("What is you password? ")
  27. if logins.get(username) == password:
  28. print("That is correct")
  29. return username
  30. else:
  31. print("try again")
  32. print("Too many tries")
  33. return False
  34.  
  35. if existingUser():
  36. quizSelection()
Add Comment
Please, Sign In to add comment