diff --git a/src/main/java/mate/academy/service/AuthenticationService.java b/src/main/java/mate/academy/service/AuthenticationService.java index 8f7c7c97..bd27cd2f 100644 --- a/src/main/java/mate/academy/service/AuthenticationService.java +++ b/src/main/java/mate/academy/service/AuthenticationService.java @@ -1,6 +1,8 @@ package mate.academy.service; public class AuthenticationService { + private UserService userService = new UserService(); + /** * Imagine that some user wants to login to your site. * You should check if user credentials (login and password) are valid or not. @@ -11,6 +13,7 @@ public class AuthenticationService { * Return false in any other cases. */ public boolean login(String email, String password) { - return false; + return userService.findByEmail(email) != null ? userService.findByEmail(email) + .getPassword().equals(password) : false; } } diff --git a/src/main/java/mate/academy/service/UserService.java b/src/main/java/mate/academy/service/UserService.java index 1652d7d6..d19b7afe 100644 --- a/src/main/java/mate/academy/service/UserService.java +++ b/src/main/java/mate/academy/service/UserService.java @@ -3,6 +3,7 @@ import mate.academy.model.User; public class UserService { + private static final User[] users = new User[] { new User("bob@i.ua", "1234"), new User("alice@i.ua", "1234") @@ -15,6 +16,11 @@ public class UserService { * Return null if there is no suitable user */ public User findByEmail(String email) { + for (User user : users) { + if (user.getEmail().equals(email)) { + return user; + } + } return null; } }