From 6005aada08bd85292066d5b99139bfd344723a37 Mon Sep 17 00:00:00 2001 From: Yevhen Date: Mon, 18 Nov 2024 17:00:48 +0100 Subject: [PATCH 1/3] executed 1 --- .../core/basesyntax/PasswordValidationException.java | 6 +++++- src/main/java/core/basesyntax/PasswordValidator.java | 4 +++- src/main/java/core/basesyntax/UserService.java | 9 +++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/core/basesyntax/PasswordValidationException.java b/src/main/java/core/basesyntax/PasswordValidationException.java index c9e7ed3e7..eefc064d8 100644 --- a/src/main/java/core/basesyntax/PasswordValidationException.java +++ b/src/main/java/core/basesyntax/PasswordValidationException.java @@ -1,3 +1,7 @@ package core.basesyntax; -//write your code here +public class PasswordValidationException extends RuntimeException { + public PasswordValidationException(String massage) { + super(massage); + } +} \ No newline at end of file diff --git a/src/main/java/core/basesyntax/PasswordValidator.java b/src/main/java/core/basesyntax/PasswordValidator.java index d4655c9f5..c9ed14bf8 100644 --- a/src/main/java/core/basesyntax/PasswordValidator.java +++ b/src/main/java/core/basesyntax/PasswordValidator.java @@ -2,6 +2,8 @@ public class PasswordValidator { public void validate(String password, String repeatPassword) { - //write your code here + if(password == null || repeatPassword == null || !password.equals(repeatPassword) || password.length() < 10) { + throw new PasswordValidationException("Wrong passwords "); + } } } diff --git a/src/main/java/core/basesyntax/UserService.java b/src/main/java/core/basesyntax/UserService.java index 52f08d130..c6651f94a 100644 --- a/src/main/java/core/basesyntax/UserService.java +++ b/src/main/java/core/basesyntax/UserService.java @@ -1,10 +1,15 @@ package core.basesyntax; public class UserService { +private PasswordValidator passwordValidator = new PasswordValidator(); public void registerUser(User user) { - //write your code here + try { + passwordValidator.validate(user.getPassword(), user.getRepeatPassword()); + saveUser(user); + } catch (PasswordValidationException e) { + System.out.println("Your passwords are incorrect. Try again."); + } } - public void saveUser(User user) { System.out.println("User " + user.toString() + " was saved to database!!!"); } From f7316b9c7311d1fdb27b3072978eca31a04e0029 Mon Sep 17 00:00:00 2001 From: Yevhen Date: Mon, 18 Nov 2024 17:29:53 +0100 Subject: [PATCH 2/3] executed 2 --- .../java/core/basesyntax/PasswordValidationException.java | 2 +- src/main/java/core/basesyntax/UserService.java | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/core/basesyntax/PasswordValidationException.java b/src/main/java/core/basesyntax/PasswordValidationException.java index eefc064d8..41b5090e9 100644 --- a/src/main/java/core/basesyntax/PasswordValidationException.java +++ b/src/main/java/core/basesyntax/PasswordValidationException.java @@ -4,4 +4,4 @@ public class PasswordValidationException extends RuntimeException { public PasswordValidationException(String massage) { super(massage); } -} \ No newline at end of file +} diff --git a/src/main/java/core/basesyntax/UserService.java b/src/main/java/core/basesyntax/UserService.java index c6651f94a..648618c9e 100644 --- a/src/main/java/core/basesyntax/UserService.java +++ b/src/main/java/core/basesyntax/UserService.java @@ -1,7 +1,8 @@ package core.basesyntax; public class UserService { -private PasswordValidator passwordValidator = new PasswordValidator(); + private PasswordValidator passwordValidator = new PasswordValidator(); + public void registerUser(User user) { try { passwordValidator.validate(user.getPassword(), user.getRepeatPassword()); @@ -9,6 +10,7 @@ public void registerUser(User user) { } catch (PasswordValidationException e) { System.out.println("Your passwords are incorrect. Try again."); } + } public void saveUser(User user) { System.out.println("User " + user.toString() + " was saved to database!!!"); From 2594b823bbd5a0d7c625e5544bf7c5cb12d1e34f Mon Sep 17 00:00:00 2001 From: Yevhen Date: Mon, 18 Nov 2024 19:04:30 +0100 Subject: [PATCH 3/3] executed 3 --- .../core/basesyntax/PasswordValidationException.java | 2 +- src/main/java/core/basesyntax/PasswordValidator.java | 10 +++++++--- src/main/java/core/basesyntax/UserService.java | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/core/basesyntax/PasswordValidationException.java b/src/main/java/core/basesyntax/PasswordValidationException.java index 41b5090e9..7e318120a 100644 --- a/src/main/java/core/basesyntax/PasswordValidationException.java +++ b/src/main/java/core/basesyntax/PasswordValidationException.java @@ -1,6 +1,6 @@ package core.basesyntax; -public class PasswordValidationException extends RuntimeException { +public class PasswordValidationException extends Exception { public PasswordValidationException(String massage) { super(massage); } diff --git a/src/main/java/core/basesyntax/PasswordValidator.java b/src/main/java/core/basesyntax/PasswordValidator.java index c9ed14bf8..0b1b0abaf 100644 --- a/src/main/java/core/basesyntax/PasswordValidator.java +++ b/src/main/java/core/basesyntax/PasswordValidator.java @@ -1,9 +1,13 @@ package core.basesyntax; public class PasswordValidator { - public void validate(String password, String repeatPassword) { - if(password == null || repeatPassword == null || !password.equals(repeatPassword) || password.length() < 10) { - throw new PasswordValidationException("Wrong passwords "); + public void validate(String password, String repeatPassword) + throws PasswordValidationException { + if (password == null + || repeatPassword == null + || !password.equals(repeatPassword) + || password.length() < 10) { + throw new PasswordValidationException("Wrong passwords"); } } } diff --git a/src/main/java/core/basesyntax/UserService.java b/src/main/java/core/basesyntax/UserService.java index 648618c9e..c4e7129b0 100644 --- a/src/main/java/core/basesyntax/UserService.java +++ b/src/main/java/core/basesyntax/UserService.java @@ -12,6 +12,7 @@ public void registerUser(User user) { } } + public void saveUser(User user) { System.out.println("User " + user.toString() + " was saved to database!!!"); }