Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Log in system with a feature of changing username and password
- """
- def input_func(part): # 1, the user will be inputting here the choice of what he want to do.
- if part == 1: # part 1 == while not logged in | part 2 == while logged in.
- while True:
- choice = input(""""Input the number of your choice:
- 1. Sing up
- 2. Login
- 7. Exit\n""")
- try:
- choice = int(choice)
- except ValueError:
- print('Input the number of your choice')
- continue
- if choice == 1 or choice == 2 or choice == 7:
- break
- else:
- print('Invalid number')
- continue
- return choice
- if part == 2:
- while True:
- choice2 = input(""""Input the number of your choice:
- 3. Change password
- 4. Change username
- 5. Logout
- 7. Exit\n""")
- try:
- choice2 = int(choice2)
- except ValueError:
- print('Input the number of your choice')
- continue
- if choice2 == 3 or choice2 == 4 or choice2 == 5 or choice2 == 7:
- break
- else:
- print('Invalid number')
- continue
- return choice2
- def sign_up_system(): # 2, function that responsible for the signing up.
- user_name = input('Input Username: ')
- password = input('Input password: ')
- info_storage[user_name] = password
- print('Registered! Username: ', user_name, '''
- Password: ''', password)
- def change_pass(): # 3, function that changes your pass.
- new_pass = input('Type your new password: ')
- print('Your new password is: '), new_pass
- return new_pass
- def change_usrname(): # 4, function that changes your user name.
- new_username = input('Type your new password: ')
- print('Your new password is: ', new_username)
- return new_username
- def check_login(username, password):
- if info_storage[username] == password:
- return True
- else:
- return False
- def main(): # The main function that includes everything and runs the program.
- print("Hi welcome to the Login system\n")
- info_storage = {}
- global info_storage
- done = False
- while not done:
- logged_in = False
- while not logged_in:
- choice = input_func(1)
- if choice == 1: # Sign up
- sign_up_system()
- elif choice == 2:
- while check_login() is not True: # Log in checks checks if the user and pass are valid or not.
- log_in_user_name = input('Username: \n')
- log_in_user_pass = input('Password: ')
- check_login(log_in_user_name, log_in_user_pass)
- if check_login is False:
- 'Invalid username or password'
- elif check_login is True:
- logged_in = True
- elif choice == 7: # Exit
- done = True
- while logged_in:
- choice2 = input_func(2) # input function part 2
- if choice2 == 3: # change password
- new_pass = change_pass()
- info_storage[log_in_user_name] = new_pass
- elif choice2 == 4: # Change username
- new_username = change_usrname()
- info_storage[new_username] = info_storage.pop(log_in_user_name)
- elif choice2 == 5: # Logout
- logged_in = False
- elif choice2 == 7: # Exit
- done = True
- if __name__ == '__main__':
- main()
- TRACEBACK:
- C:\Users\Jony\venv\untitled\Scripts\python.exe "C:/untitled/Projects/Login syste,/log_in.py"
- File "C:/untitled/Projects/Login syste,/log_in.py", line 86
- global info_storage
- ^
- SyntaxError: name 'info_storage' is assigned to before global declaration
- Process finished with exit code 1
Add Comment
Please, Sign In to add comment