Guest User

Sys log

a guest
Feb 5th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.09 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.     info_storage[user_name] = password
  59.     print('Registered! Username: ', user_name, '''
  60.    Password: ''', password)
  61.  
  62.  
  63. def change_pass():       # 3, function that changes your pass.
  64.     new_pass = input('Type your new password: ')
  65.     print('Your new password is: '), new_pass
  66.     return new_pass
  67.  
  68.  
  69. def change_usrname():    # 4, function that changes your user name.
  70.     new_username = input('Type your new password: ')
  71.     print('Your new password is: ', new_username)
  72.     return new_username
  73.  
  74.  
  75. def check_login(username, password):
  76.     if info_storage[username] == password:
  77.         return True
  78.     else:
  79.         return False
  80.  
  81.  
  82. def main():              # The main function that includes everything and runs the program.
  83.     print("Hi welcome to the Login system\n")
  84.  
  85.     info_storage = {}
  86.     global info_storage
  87.  
  88.     done = False
  89.     while not done:
  90.         logged_in = False
  91.         while not logged_in:
  92.             choice = input_func(1)
  93.  
  94.             if choice == 1:  # Sign up
  95.                 sign_up_system()
  96.  
  97.             elif choice == 2:
  98.                 while check_login() is not True:  # Log in checks checks if the user and pass are valid or not.
  99.                     log_in_user_name = input('Username: \n')
  100.                     log_in_user_pass = input('Password: ')
  101.                     check_login(log_in_user_name, log_in_user_pass)
  102.  
  103.                     if check_login is False:
  104.                         'Invalid username or password'
  105.  
  106.                     elif check_login is True:
  107.                         logged_in = True
  108.  
  109.             elif choice == 7:  # Exit
  110.                 done = True
  111.  
  112.         while logged_in:
  113.             choice2 = input_func(2)  # input function part 2
  114.  
  115.             if choice2 == 3:  # change password
  116.                 new_pass = change_pass()
  117.                 info_storage[log_in_user_name] = new_pass
  118.  
  119.             elif choice2 == 4:  # Change username
  120.                 new_username = change_usrname()
  121.                 info_storage[new_username] = info_storage.pop(log_in_user_name)
  122.  
  123.             elif choice2 == 5:  # Logout
  124.                 logged_in = False
  125.  
  126.             elif choice2 == 7:  # Exit
  127.                 done = True
  128.  
  129.  
  130. if __name__ == '__main__':
  131.     main()
  132.  
  133.  
  134. TRACEBACK:
  135.  
  136. C:\Users\Jony\venv\untitled\Scripts\python.exe "C:/untitled/Projects/Login syste,/log_in.py"
  137.   File "C:/untitled/Projects/Login syste,/log_in.py", line 86
  138.     global info_storage
  139.     ^
  140. SyntaxError: name 'info_storage' is assigned to before global declaration
  141.  
  142. Process finished with exit code 1
Add Comment
Please, Sign In to add comment