Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/main/java/core/basesyntax/PasswordValidationException.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
package core.basesyntax;

//write your code here
public class PasswordValidationException extends Exception {
/**
* Constructs a new exception with the specified detail message. The
* cause is not initialized, and may subsequently be initialized by
* a call to {@link #initCause}.
*
* @param message the detail message. The detail message is saved for
* later retrieval by the {@link #getMessage()} method.
*/
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 == null || !password.equals(repeatPassword)
|| password.length() < 10) {
throw new PasswordValidationException("Wrong passwords");
}
}
}
12 changes: 12 additions & 0 deletions src/main/java/core/basesyntax/UserService.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
package core.basesyntax;

public class UserService {
private final PasswordValidator validator = new PasswordValidator();

public void registerUser(User user) {
//write your code here
if (user == null) {
System.out.println("User cannot be null");
return;
}
try {
validator.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