From 0a094d3aa3d66d4a97575dfe2cf9a8a53921a98e Mon Sep 17 00:00:00 2001 From: Yevhen Date: Sat, 16 Nov 2024 13:44:31 +0100 Subject: [PATCH 1/3] excuted --- .../java/core/basesyntax/PasswordValidationException.java | 6 +++++- src/main/java/core/basesyntax/PasswordValidator.java | 4 +++- src/main/java/core/basesyntax/UserService.java | 1 - 3 files changed, 8 insertions(+), 3 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..8f83f9f22 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..fbda1a3f8 100644 --- a/src/main/java/core/basesyntax/UserService.java +++ b/src/main/java/core/basesyntax/UserService.java @@ -2,7 +2,6 @@ public class UserService { public void registerUser(User user) { - //write your code here } public void saveUser(User user) { From 90d7d0376f3d3d4d6c014555d24f01f72466df73 Mon Sep 17 00:00:00 2001 From: Yevhen Date: Sun, 17 Nov 2024 17:17:57 +0100 Subject: [PATCH 2/3] made changes --- src/main/java/core/basesyntax/UserService.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/core/basesyntax/UserService.java b/src/main/java/core/basesyntax/UserService.java index fbda1a3f8..70eb43b9a 100644 --- a/src/main/java/core/basesyntax/UserService.java +++ b/src/main/java/core/basesyntax/UserService.java @@ -1,9 +1,16 @@ package core.basesyntax; public class UserService { +private PasswordValidator passwordValidator = new PasswordValidator(); public void registerUser(User user) { + 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 e4bd0fe875320746866bba788ede8f38ab892380 Mon Sep 17 00:00:00 2001 From: Yevhen Date: Sun, 17 Nov 2024 17:22:34 +0100 Subject: [PATCH 3/3] made changes --- src/main/java/core/basesyntax/UserService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/core/basesyntax/UserService.java b/src/main/java/core/basesyntax/UserService.java index 70eb43b9a..c6651f94a 100644 --- a/src/main/java/core/basesyntax/UserService.java +++ b/src/main/java/core/basesyntax/UserService.java @@ -7,7 +7,6 @@ public void registerUser(User user) { passwordValidator.validate(user.getPassword(), user.getRepeatPassword()); saveUser(user); } catch (PasswordValidationException e) { - // Обробка виключення System.out.println("Your passwords are incorrect. Try again."); } }