Skip to content

Commit

Permalink
the code has been improved in terms of writing rules
Browse files Browse the repository at this point in the history
  • Loading branch information
har1as committed Feb 22, 2025
1 parent 7afd7d7 commit 6af6c69
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/main/java/mate/academy/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public static void main(String[] args) {
test("[email protected]", "1234", false);
test("[email protected]", "qwerty", false);
}

private static void test(String email, String password, boolean expected) {
boolean actual = authenticationService.login(email, password);

Expand Down
11 changes: 3 additions & 8 deletions src/main/java/mate/academy/service/AuthenticationService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

public class AuthenticationService {
private final 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.
Expand All @@ -17,14 +18,8 @@ public boolean login(String email, String password) {
User user = userService.findByEmail(email);

if (user != null) {


if (!user.getPassword().equals(password)) {
return false;
} else {
return true;
}
return user.getPassword().equals(password);
}
return user != null && user.getPassword().equals(password);
return false;
}
}
3 changes: 0 additions & 3 deletions src/main/java/mate/academy/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import mate.academy.model.User;

import java.util.Scanner;

public class UserService {
private static final User[] users = new User[] {
new User("[email protected]", "1234"),
Expand All @@ -16,7 +14,6 @@ public class UserService {
* @return - user if his email is equal to passed email.
* Return <code>null</code> if there is no suitable user
*/

public User findByEmail(String email) {
for (User user : users) { // Для отладки
if (user.getEmail().equals(email)) {
Expand Down

0 comments on commit 6af6c69

Please sign in to comment.