Advertisement
Guest User

Log sys taceback

a guest
Feb 5th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.07 KB | None | 0 0
  1. """
  2.  
  3.    Log in system with a feature of changing username and password
  4.  
  5. """
  6.  
  7.  
  8. def input_func(part):        # 1, the user will be inputting here the choice of what he want to do.
  9.     if part == 1:            # part 1 == while not logged in | part 2 == while logged in.
  10.         while True:
  11.             choice = input(""""Input the number of your choice:
  12.            1. Sing up
  13.            2. Login
  14.            7. Exit\n""")
  15.             try:
  16.                 choice = int(choice)
  17.  
  18.             except ValueError:
  19.                 print('Input the number of your choice')
  20.                 continue
  21.  
  22.             if choice == 1 or choice == 2 or choice == 7:
  23.                 break
  24.  
  25.             else:
  26.                 print('Invalid number')
  27.                 continue
  28.  
  29.         return choice
  30.  
  31.     if part == 2:
  32.         while True:
  33.             choice2 = input(""""Input the number of your choice:
  34.            3. Change password
  35.            4. Change username
  36.            5. Logout
  37.            7. Exit\n""")
  38.             try:
  39.                 choice2 = int(choice2)
  40.  
  41.             except ValueError:
  42.                 print('Input the number of your choice')
  43.                 continue
  44.  
  45.             if choice2 == 3 or choice2 == 4 or choice2 == 5 or choice2 == 7:
  46.                 break
  47.  
  48.             else:
  49.                 print('Invalid number')
  50.                 continue
  51.  
  52.         return choice2
  53.  
  54.  
  55. def sign_up_system():    # 2, function that responsible for the signing up.
  56.     user_name = input('Input Username: ')
  57.     password = input('Input password: ')
  58.     return user_name, password
  59.  
  60.  
  61. def change_pass():       # 3, function that changes your pass.
  62.     new_pass = input('Type your new password: ')
  63.     print('Your new password is: '), new_pass
  64.     return new_pass
  65.  
  66.  
  67. def change_usrname():    # 4, function that changes your user name.
  68.     new_username = input('Type your new password: ')
  69.     print('Your new password is: ', new_username)
  70.     return new_username
  71.  
  72.  
  73. def users_storage(part, users_name, users_pass, old_user):       # 5, checks if the user and pass are valid.
  74.                                     # part 1 == the sign up | part 2 == login check | part 3 == change pass | part 4 == change username
  75.     users_storage = {}
  76.     if part == 1:
  77.         users_storage[users_name] = users_pass
  78.  
  79.     elif part == 2:
  80.         if users_storage[users_name] == users_pass:
  81.             return True
  82.         else:
  83.             return False
  84.  
  85.     elif part == 3:
  86.         users_storage[users_name] = users_pass
  87.  
  88.     elif part == 4:
  89.         users_storage[users_name] = users_storage.pop(old_user)
  90.  
  91.  
  92. def main():              # The main function that includes everything and runs the program.
  93.     print("Hi welcome to the Login system\n")
  94.     done = False
  95.     while not done:
  96.         logged_in = False
  97.         while not logged_in:
  98.             choice = input_func(1)
  99.  
  100.             if choice == 1:  # Sign up
  101.                 sign_up_user_name, sign_up_user_pass = sign_up_system()
  102.                 users_storage(1, sign_up_user_name, sign_up_user_pass, None)
  103.  
  104.             elif choice == 2:
  105.                 login_check = False
  106.                 while not login_check:  # Log in checks checks if the user and pass are valid or not.
  107.                     log_in_user_name = input('Username: \n')
  108.                     log_in_user_pass = input('Password: ')
  109.  
  110.                     login_check = users_storage(2, log_in_user_name, log_in_user_pass, None)
  111.  
  112.                     if login_check == False:
  113.                         'Invalid username or password'
  114.  
  115.                     elif login_check == True:
  116.                         logged_in = True
  117.  
  118.             elif choice == 7:  # Exit
  119.                 done = True
  120.  
  121.         while logged_in:
  122.             choice2 = input_func(2)  # input function part 2
  123.  
  124.             if choice2 == 3:  # change password
  125.                 new_pass = change_pass()
  126.                 users_storage(3, log_in_user_name, new_pass, None)
  127.  
  128.             elif choice2 == 4:  # Change username
  129.                 new_username = change_usrname()
  130.                 users_storage(4, new_username, log_in_user_pass, log_in_user_name)
  131.  
  132.             elif choice2 == 5:  # Logout
  133.                 logged_in = False
  134.  
  135.             elif choice2 == 7:  # Exit
  136.                 done = True
  137.  
  138.  
  139. if __name__ == '__main__':
  140.     main()
  141.  
  142.  
  143.  
  144. TRACEBACK:
  145. Hi welcome to the Login system
  146.  
  147. "Input the number of your choice:
  148.            1. Sing up
  149.            2. Login
  150.            7. Exit
  151. 1
  152. Input Username: j
  153. Input password: j
  154. "Input the number of your choice:
  155.             1. Sing up
  156.             2. Login
  157.             7. Exit
  158. 2
  159. Username:
  160. j
  161. Password: j
  162. Traceback (most recent call last):
  163.   File "C:/untitled/Projects/Login syste,/log_in.py", line 140, in <module>
  164.     main()
  165.   File "C:/untitled/Projects/Login syste,/log_in.py", line 110, in main
  166.     login_check = users_storage(2, log_in_user_name, log_in_user_pass, None)
  167.   File "C:/untitled/Projects/Login syste,/log_in.py", line 80, in users_storage
  168.     if users_storage[users_name] == users_pass:
  169. KeyError: 'j'
  170.  
  171. Process finished with exit code 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement