Skip to content
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
package core.basesyntax;

//write your code here
public class PasswordValidationException extends Exception {
public PasswordValidationException() {
super();
}

public PasswordValidationException(String message) {
super(message);
}
}
7 changes: 6 additions & 1 deletion src/main/java/core/basesyntax/PasswordValidator.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package core.basesyntax;

public class PasswordValidator {
public void validate(String password, String repeatPassword) {
public void validate(String password, String repeatPassword) throws PasswordValidationException {
//write your code here
if (password.length() >= 10 && repeatPassword.length() >= 10 && repeatPassword.equals(password)) {
System.out.println("Password matches");
} else {
throw new PasswordValidationException("Wrong passwords");
}
}
}
9 changes: 9 additions & 0 deletions src/main/java/core/basesyntax/UserService.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
package core.basesyntax;

public class UserService {

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) {
throw new RuntimeException(e);
}
}

public void saveUser(User user) {
Expand Down
Loading