Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implements base task logic #1330

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
package core.basesyntax;

//write your code here
import java.io.IOException;

public class PasswordValidationException extends IOException {
public PasswordValidationException(String message) {
super(message);
}
}
10 changes: 8 additions & 2 deletions src/main/java/core/basesyntax/PasswordValidator.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package core.basesyntax;

import java.util.Objects;

public class PasswordValidator {
public void validate(String password, String repeatPassword) {
//write your code here
public void validate(String password, String repeatPassword)
throws PasswordValidationException {
if (password == null && repeatPassword == null || !Objects.equals(password, repeatPassword)
|| password.toCharArray().length < 10) {
throw new PasswordValidationException("Wrong passwords");
}
}
}
7 changes: 6 additions & 1 deletion src/main/java/core/basesyntax/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

public class UserService {
public void registerUser(User user) {
//write your code here
try {
new 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) {
Expand Down
Loading