From 898b9a282b347b65a9fbe1ba63ce322641e33686 Mon Sep 17 00:00:00 2001 From: Vladyslav Opolskyi Date: Tue, 5 Nov 2024 15:24:04 +0100 Subject: [PATCH] solved exercise --- .../java/mate/academy/service/AuthenticationService.java | 7 ++++++- src/main/java/mate/academy/service/UserService.java | 7 +++++++ 2 files changed, 13 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..53dacc4e5 100644 --- a/src/main/java/mate/academy/service/AuthenticationService.java +++ b/src/main/java/mate/academy/service/AuthenticationService.java @@ -11,6 +11,11 @@ public class AuthenticationService { * Return false in any other cases. */ public boolean login(String email, String password) { - return false; + + UserService userService = new UserService(); + if (userService.findByEmail(email) == null) { + return false; + } + return password.equals(userService.findByEmail(email).getPassword()); } } diff --git a/src/main/java/mate/academy/service/UserService.java b/src/main/java/mate/academy/service/UserService.java index 1652d7d68..e50e35036 100644 --- a/src/main/java/mate/academy/service/UserService.java +++ b/src/main/java/mate/academy/service/UserService.java @@ -15,6 +15,13 @@ public class UserService { * Return null if there is no suitable user */ public User findByEmail(String email) { + + for (int i = 0; i < users.length; i++) { + + if(users[i].getEmail().equals(email)) { + return users[i]; + } + } return null; } }