Skip to content

Instantly share code, notes, and snippets.

@adrianvdh
Last active December 24, 2017 06:52
Show Gist options
  • Save adrianvdh/fe692e0c848a69b36e1a68691f5bda4a to your computer and use it in GitHub Desktop.
Save adrianvdh/fe692e0c848a69b36e1a68691f5bda4a to your computer and use it in GitHub Desktop.
class UserService {
List<User> users = new ArrayList<>();
{
User user = new User();
user.username = "adrianvdh";
user.password = "hello123";
users.add(user);
}
public User authenticate(String username, String password) {
User foundUser = null;
for (User userInCollection : users) {
if (userInCollection.username.equals(username)) {
foundUser = userInCollection;
break;
}
}
if(foundUser == null)
throw new RuntimeException(String.format("User with username %s could not be found!", username));
return foundUser;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment