Advertisement
Guest User

Untitled

a guest
Mar 10th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. file = open("logindata.txt", "r")
  2. data_list = file.readlines()
  3. file.close()
  4. print(data_list)
  5.  
  6.  
  7. for i in range(0, len(data_list)):
  8. username = input("username: ")
  9. password = input("password: ")
  10. i += 1
  11. if i % 2 == 0:
  12. if data_list[i] == username and data_list[i + 1] == password:
  13. print("You are successfully logged in as", username)
  14. i == len(data_list)
  15. elif data_list[i] == username and data_list[i + 1] != password:
  16. print("The password you entered was incorrect, please try again.")
  17. else: # how do i end the code if the user inputs no
  18. if data_list[i] != username:
  19. choice = input("The username you entered was not found, would you like to create an account? (Y/N)")
  20. if choice.upper() == "Y":
  21. new_username = input("new username: ")
  22. data_list.append(new_username + "n")
  23. new_password = input("new password: ")
  24. data_list.append(new_password + "n")
  25. file = open("logindata.txt", "w")
  26. file.writelines(data_list)
  27. i == data_list
  28.  
  29. em # username
  30. car # password
  31. hola # username
  32. bye # password
  33.  
  34. def does_username_exists(username, login_file_path):
  35. username_exists = False
  36. user_password = None
  37. with open(login_file_path) as login_file:
  38. while True:
  39. username_line = login_file.readline()
  40. if not username_line: break
  41. password_line = login_file.readline()
  42. if not password_line: break
  43. if username == username_line.strip():
  44. username_exists = True
  45. user_password = password_line.strip()
  46. break
  47.  
  48. return username_exists, user_password
  49.  
  50.  
  51. def main():
  52. login_file_path = "logindata.txt"
  53.  
  54. username = input("Enter username: ")
  55. username_exists, user_password = does_username_exists(username, login_file_path)
  56. if not username_exists:
  57. choice = input("The username you entered was not found, would you like to create an account? (Y/N)")
  58. if choice.upper() == 'Y':
  59. new_username = input("Enter new username: ")
  60. new_password = input("Enter new password: ")
  61. with open(login_file_path, "a") as login_file:
  62. login_file.write(new_username + "n")
  63. login_file.write(new_password + "n")
  64. return
  65.  
  66. password = input("Enter password: ")
  67. if not (password == user_password):
  68. print("The password you entered was incorrect, please try again.")
  69. else:
  70. print("You are successfully logged in as - '{}'".format(username))
  71.  
  72.  
  73. if __name__ == "__main__":
  74. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement