diff --git a/src/main/java/mate/academy/service/AuthenticationService.java b/src/main/java/mate/academy/service/AuthenticationService.java index 8f7c7c975..0afd140af 100644 --- a/src/main/java/mate/academy/service/AuthenticationService.java +++ b/src/main/java/mate/academy/service/AuthenticationService.java @@ -1,5 +1,7 @@ package mate.academy.service; +import mate.academy.model.User; + public class AuthenticationService { /** * Imagine that some user wants to login to your site. @@ -10,7 +12,13 @@ public class AuthenticationService { * @return true if user by email exists and passed password is equal to user's password. * Return false in any other cases. */ + private UserService userService = new UserService(); + public boolean login(String email, String password) { - return false; + User user = this.userService.findByEmail(email); + if (user == null) { + return false; + } + return user.getPassword().equals(password); } } diff --git a/src/main/java/mate/academy/service/UserService.java b/src/main/java/mate/academy/service/UserService.java index 1652d7d68..08fa125b0 100644 --- a/src/main/java/mate/academy/service/UserService.java +++ b/src/main/java/mate/academy/service/UserService.java @@ -15,6 +15,11 @@ public class UserService { * Return null if there is no suitable user */ public User findByEmail(String email) { + for (User user : users) { + if (email.equals(user.getEmail())) { + return user; + } + } return null; } }