Advertisement
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: ')
- return user_name, 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 users_storage(part, users_name, users_pass, old_user): # 5, checks if the user and pass are valid.
- # part 1 == the sign up | part 2 == login check | part 3 == change pass | part 4 == change username
- users_storage = {}
- if part == 1:
- users_storage[users_name] = users_pass
- elif part == 2:
- if users_storage[users_name] == users_pass:
- return True
- else:
- return False
- elif part == 3:
- users_storage[users_name] = users_pass
- elif part == 4:
- users_storage[users_name] = users_storage.pop(old_user)
- def main(): # The main function that includes everything and runs the program.
- print("Hi welcome to the Login system\n")
- done = False
- while not done:
- logged_in = False
- while not logged_in:
- choice = input_func(1)
- if choice == 1: # Sign up
- sign_up_user_name, sign_up_user_pass = sign_up_system()
- users_storage(1, sign_up_user_name, sign_up_user_pass, None)
- elif choice == 2:
- login_check = False
- while not login_check: # 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: ')
- login_check = users_storage(2, log_in_user_name, log_in_user_pass, None)
- if login_check == False:
- 'Invalid username or password'
- elif login_check == 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()
- users_storage(3, log_in_user_name, new_pass, None)
- elif choice2 == 4: # Change username
- new_username = change_usrname()
- users_storage(4, new_username, log_in_user_pass, log_in_user_name)
- elif choice2 == 5: # Logout
- logged_in = False
- elif choice2 == 7: # Exit
- done = True
- if __name__ == '__main__':
- main()
- TRACEBACK:
- Hi welcome to the Login system
- "Input the number of your choice:
- 1. Sing up
- 2. Login
- 7. Exit
- 1
- Input Username: j
- Input password: j
- "Input the number of your choice:
- 1. Sing up
- 2. Login
- 7. Exit
- 2
- Username:
- j
- Password: j
- Traceback (most recent call last):
- File "C:/untitled/Projects/Login syste,/log_in.py", line 140, in <module>
- main()
- File "C:/untitled/Projects/Login syste,/log_in.py", line 110, in main
- login_check = users_storage(2, log_in_user_name, log_in_user_pass, None)
- File "C:/untitled/Projects/Login syste,/log_in.py", line 80, in users_storage
- if users_storage[users_name] == users_pass:
- KeyError: 'j'
- Process finished with exit code 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement