From b4940e762f8a684d592bac12b8e8dceae69f7364 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=86=D0=BB=D0=BB=D1=8F=20=D0=9B=D0=B0=D0=B7=D0=B0=D1=80?= =?UTF-8?q?=D0=B5=D0=B2?= <108271589+bagouser123@users.noreply.github.com> Date: Thu, 12 Oct 2023 20:15:08 +0300 Subject: [PATCH 1/4] doing the task of passwords and repeat passwords --- .../java/core/basesyntax/PasswordValidationException.java | 6 +++++- src/main/java/core/basesyntax/PasswordValidator.java | 6 ++++-- src/main/java/core/basesyntax/UserService.java | 8 +++++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main/java/core/basesyntax/PasswordValidationException.java b/src/main/java/core/basesyntax/PasswordValidationException.java index c9e7ed3e7..97bfa71e0 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 Exception { + public PasswordValidationException (String message) { + super(message); + } +} diff --git a/src/main/java/core/basesyntax/PasswordValidator.java b/src/main/java/core/basesyntax/PasswordValidator.java index d4655c9f5..09a26522e 100644 --- a/src/main/java/core/basesyntax/PasswordValidator.java +++ b/src/main/java/core/basesyntax/PasswordValidator.java @@ -1,7 +1,9 @@ package core.basesyntax; public class PasswordValidator { - public void validate(String password, String repeatPassword) { - //write your code here + public static 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 52f08d130..70683782c 100644 --- a/src/main/java/core/basesyntax/UserService.java +++ b/src/main/java/core/basesyntax/UserService.java @@ -2,7 +2,13 @@ public class UserService { 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) { From 582d4abc4dd6daaeb926dda53e9a1888cfee94db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=86=D0=BB=D0=BB=D1=8F=20=D0=9B=D0=B0=D0=B7=D0=B0=D1=80?= =?UTF-8?q?=D0=B5=D0=B2?= <108271589+bagouser123@users.noreply.github.com> Date: Thu, 12 Oct 2023 20:42:37 +0300 Subject: [PATCH 2/4] doing the task of passwords and repeat passwords --- .../java/core/basesyntax/PasswordValidationException.java | 6 +++--- src/main/java/core/basesyntax/PasswordValidator.java | 6 ++++-- src/main/java/core/basesyntax/UserService.java | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/core/basesyntax/PasswordValidationException.java b/src/main/java/core/basesyntax/PasswordValidationException.java index 97bfa71e0..b47ef048d 100644 --- a/src/main/java/core/basesyntax/PasswordValidationException.java +++ b/src/main/java/core/basesyntax/PasswordValidationException.java @@ -1,7 +1,7 @@ package core.basesyntax; public class PasswordValidationException extends Exception { - public PasswordValidationException (String message) { - super(message); - } + public PasswordValidationException (String message) { + super(message); + } } diff --git a/src/main/java/core/basesyntax/PasswordValidator.java b/src/main/java/core/basesyntax/PasswordValidator.java index 09a26522e..fc90eca18 100644 --- a/src/main/java/core/basesyntax/PasswordValidator.java +++ b/src/main/java/core/basesyntax/PasswordValidator.java @@ -1,8 +1,10 @@ package core.basesyntax; public class PasswordValidator { - public static void validate(String password, String repeatPassword) throws PasswordValidationException { - if (password == null || repeatPassword == null || !password.equals(repeatPassword) || password.length() < 10) { + public static 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 70683782c..3bb162884 100644 --- a/src/main/java/core/basesyntax/UserService.java +++ b/src/main/java/core/basesyntax/UserService.java @@ -5,10 +5,10 @@ public void registerUser(User user) { try { PasswordValidator.validate(user.getPassword(),user.getRepeatPassword()); saveUser(user); - } catch(PasswordValidationException e) { + } catch (PasswordValidationException e) { System.out.println("Your passwords are incorrect. Try again."); - } + } } public void saveUser(User user) { From 6d2a1c782d3ea227137cce20f3b122248dc80fbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=86=D0=BB=D0=BB=D1=8F=20=D0=9B=D0=B0=D0=B7=D0=B0=D1=80?= =?UTF-8?q?=D0=B5=D0=B2?= <108271589+bagouser123@users.noreply.github.com> Date: Thu, 12 Oct 2023 20:49:29 +0300 Subject: [PATCH 3/4] doing the task of passwords and repeat passwords --- src/main/java/core/basesyntax/PasswordValidator.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/core/basesyntax/PasswordValidator.java b/src/main/java/core/basesyntax/PasswordValidator.java index fc90eca18..46b702f9f 100644 --- a/src/main/java/core/basesyntax/PasswordValidator.java +++ b/src/main/java/core/basesyntax/PasswordValidator.java @@ -3,9 +3,9 @@ public class PasswordValidator { public static void validate(String password, String repeatPassword) throws PasswordValidationException { - if (password == null || repeatPassword == null || !password.equals(repeatPassword) - || password.length() < 10) { - throw new PasswordValidationException("Wrong passwords"); + if (password == null || repeatPassword == null || !password.equals(repeatPassword) + || password.length() < 10) { + throw new PasswordValidationException("Wrong passwords"); } } } From 24b835219f09a1684c1a8707b5fa69e1c5a6a988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=86=D0=BB=D0=BB=D1=8F=20=D0=9B=D0=B0=D0=B7=D0=B0=D1=80?= =?UTF-8?q?=D0=B5=D0=B2?= <108271589+bagouser123@users.noreply.github.com> Date: Thu, 12 Oct 2023 20:54:37 +0300 Subject: [PATCH 4/4] doing the task of passwords and repeat passwords --- src/main/java/core/basesyntax/PasswordValidationException.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/core/basesyntax/PasswordValidationException.java b/src/main/java/core/basesyntax/PasswordValidationException.java index b47ef048d..70c1d49fd 100644 --- a/src/main/java/core/basesyntax/PasswordValidationException.java +++ b/src/main/java/core/basesyntax/PasswordValidationException.java @@ -1,7 +1,7 @@ package core.basesyntax; public class PasswordValidationException extends Exception { - public PasswordValidationException (String message) { + public PasswordValidationException(String message) { super(message); } }