Guest User

Untitled

a guest
Dec 8th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. class UserService {
  2.  
  3. Set<User> users = new HashSet<>();
  4.  
  5. {
  6. User user = new User();
  7. user.username = "adrianvdh";
  8. user.password = "hello123";
  9. users.add(user);
  10. }
  11.  
  12. public User authenicate(String username, String password) {
  13. User foundUser = null
  14. for (User userInCollection : users) {
  15. if (userInCollection.username.equals(username) {
  16. foundUser = userInCollection;
  17. break;
  18. }
  19. }
  20.  
  21. if(foundUser == null)
  22. throw new RuntimeException(String.format("User with username %s could not be found!", username));
  23.  
  24. return foundUser;
  25. }
  26. }
Add Comment
Please, Sign In to add comment