Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with open('abc.txt') as f:
- credentials = [x.strip().split(':') for x in f.readlines()]
- for username, password in credentials:
- user_input = input('Please Enter username: ')
- if user_input != username:
- sys.exit('Incorrect incorrect username, terminating... n')
- user_input = input('Please Enter Password: ')
- if user_input != password:
- sys.exit('Incorrect Password, terminating... n')
- print ('User is logged in!n')
- Sil:xyz123
- smith:abc321
- with open('abc.txt') as f:
- credentials = dict([x.strip().split(':') for x in f.readlines()]) # Created a dictionary with username:password items
- username_input = input('Please Enter username: ')
- if username_input not in credentials: # Check if username is in the credentials dictionary
- sys.exit('Incorrect incorrect username, terminating... n')
- password_input = input('Please Enter Password: ')
- if password_input != credentials[username_input]: # Check if the password entered matches the password in the dictionary
- sys.exit('Incorrect Password, terminating... n')
- print ('User is logged in!n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement