From ad7c6b4c16e1db06fdcc75a8ac323218060a21a1 Mon Sep 17 00:00:00 2001 From: Hanna Voloshko Date: Tue, 7 Jan 2025 00:34:11 +0200 Subject: [PATCH] all tasks are solved --- .../academy/service/AuthenticationService.java | 15 ++++++++++++++- .../java/mate/academy/service/UserService.java | 5 +++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/mate/academy/service/AuthenticationService.java b/src/main/java/mate/academy/service/AuthenticationService.java index 8f7c7c975..117b101e1 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. @@ -11,6 +13,17 @@ public class AuthenticationService { * Return false in any other cases. */ public boolean login(String email, String password) { - return false; + UserService newUserSerice = new UserService(); + User user1 = newUserSerice.findByEmail(email); + if (user1 == null) { + return false; + } else { + String correctPassword = user1.getPassword(); + if (password.equals(correctPassword)) { + return true; + } else { + return false; + } + } } } diff --git a/src/main/java/mate/academy/service/UserService.java b/src/main/java/mate/academy/service/UserService.java index 1652d7d68..6b133c766 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 element: users) { + if (email.equals(element.getEmail())) { + return element; + } + } return null; } }