Advertisement
Guest User

Untitled

a guest
Oct 6th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. with open('abc.txt') as f:
  2. credentials = [x.strip().split(':') for x in f.readlines()]
  3.  
  4. for username, password in credentials:
  5.  
  6. user_input = input('Please Enter username: ')
  7.  
  8. if user_input != username:
  9.  
  10. sys.exit('Incorrect incorrect username, terminating... n')
  11.  
  12.  
  13. user_input = input('Please Enter Password: ')
  14.  
  15.  
  16.  
  17. if user_input != password:
  18.  
  19. sys.exit('Incorrect Password, terminating... n')
  20.  
  21.  
  22.  
  23. print ('User is logged in!n')
  24.  
  25. Sil:xyz123
  26. smith:abc321
  27.  
  28. with open('abc.txt') as f:
  29. credentials = dict([x.strip().split(':') for x in f.readlines()]) # Created a dictionary with username:password items
  30.  
  31. username_input = input('Please Enter username: ')
  32.  
  33. if username_input not in credentials: # Check if username is in the credentials dictionary
  34.  
  35. sys.exit('Incorrect incorrect username, terminating... n')
  36.  
  37. password_input = input('Please Enter Password: ')
  38.  
  39. if password_input != credentials[username_input]: # Check if the password entered matches the password in the dictionary
  40.  
  41. sys.exit('Incorrect Password, terminating... n')
  42.  
  43. print ('User is logged in!n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement