Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1. # Simple messaging application. Proof of concept, but not practical
  2.  
  3. user_list = {} # Imports an empty dictionary.
  4. messages = {}
  5. print("Welcome, admin. Please select a password:")
  6. admin_password = input()
  7. print('\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n')
  8.  
  9. while 1 == 1: # Creates a recursive loop. Probably a better way to do this.
  10.  
  11. print( #Greeting message.
  12. "\n"
  13. "Press 1 to create a new account."
  14. "\nPress 2 for a current list of users. (Only usable by admin)"
  15. "\nPress 3 to send and receive messages."
  16. "\nPress 4 for help."
  17. "\nPlease enter your choice:\n"
  18. )
  19.  
  20. user_input = input() # Dictates which menu option to execute.
  21.  
  22. if user_input == '1':
  23. print("\nPlease enter your preferred name:")
  24. attempted_name = input().lower() # Disregards case.
  25. if attempted_name in user_list: # Checks if name exists
  26. print("That name is already taken. Please choose again.")
  27. else: # If name is unique, adds it to database.
  28. user_list.update({attempted_name.lower(): 'password'}) # Default password is "password" temporarily.
  29. print("Welcome to the site, "
  30. + attempted_name +
  31. "! Please choose a password:"
  32. )
  33. user_list[attempted_name] = input() # User defines new password.
  34. messages[attempted_name] = "DEFAULT MESSAGE"
  35.  
  36. elif user_input == '2': # Displays all current users and their passwords.
  37. print("Please enter admin password:")
  38. if input() == admin_password:
  39. print('\n' + str(user_list))
  40. else:
  41. print('\nPassword incorrect. Please try again.')
  42.  
  43. elif user_input == '3': # messaging other users, checking messages
  44. login_name = input("Please enter your user name: ").lower() # User login
  45. if login_name in user_list:
  46. login_password = input("Please enter password for " + login_name + ": ")
  47. if login_password == user_list[login_name]:
  48. print("\nCorrect password entered.\nPress 1 to write a message.\nPress 2 to read your message.\n")
  49. user_option = input()
  50. if user_option == '1':
  51. messaged_user = input("Please enter the name of the person you'd like to message:").lower()
  52. if messages[messaged_user] != "DEFAULT MESSAGE": # If user's message is "Default message", inbox
  53. print("User's inbox is full.") # is marked as full
  54. else:
  55. message = input("Please type your message:")
  56. messages[messaged_user] = message
  57. elif user_option == '2':
  58. print('\n' + messages[login_name])
  59. mark_read = input("Mark message as read? y/n:")
  60. if mark_read == "y":
  61. print ("\nMessage marked as 'read'.")
  62. messages[login_name] = "DEFAULT MESSAGE" # If user marks message as read, it returns to
  63. elif mark_read == "n": # default, which opens up the inbox for more
  64. print ("\nMessage not marked as 'read'.") # messages.
  65. else:
  66. print("\nInvalid option.")
  67. else:
  68. print("\n That is not a valid option.")
  69. else:
  70. print("\nPassword not valid.")
  71. else:
  72. print("\nInvalid username.")
  73.  
  74.  
  75. else: # Help message.
  76. print(
  77. "This is a simple messaging database. "
  78. "When creating a username,\nit must be unique, "
  79. "but the system will automatically\nformat your unique "
  80. "username to be in all lowercase.\n"
  81. "Passwords, however, are case-sensitive."
  82. "Messages can be sent to other users, and users "
  83. "can check their own messages."
  84. )
  85. # done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement