Skip to content

Commit

Permalink
fixed jv-checked-exception task
Browse files Browse the repository at this point in the history
  • Loading branch information
kvjohnny committed Dec 17, 2023
1 parent 223a4a7 commit be5d59f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
package core.basesyntax;

//write your code here
public class PasswordValidationException extends Exception {
public PasswordValidationException(String message) {
super(message);
}
}
9 changes: 7 additions & 2 deletions 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) {
//write your code here
public void validate(String password, String repeatPassword)
throws PasswordValidationException {
if (password == null && repeatPassword == null
|| password != null && (password.length() < 10
|| !password.equals(repeatPassword))) {
throw new PasswordValidationException("Wrong passwords");
}
}
}
8 changes: 4 additions & 4 deletions src/main/java/core/basesyntax/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public void setRepeatPassword(String repeatPassword) {
@Override
public String toString() {
return "User{"
+ "email='" + email + '\''
+ ", password='" + password + '\''
+ ", repeatPassword='" + repeatPassword + '\''
+ '}';
+ "email='" + email + '\''
+ ", password='" + password + '\''
+ ", repeatPassword='" + repeatPassword + '\''
+ '}';
}
}
9 changes: 8 additions & 1 deletion src/main/java/core/basesyntax/UserService.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package core.basesyntax;

public class UserService {
private final 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) {
System.out.println("Your passwords are incorrect. Try again.");
}
}

public void saveUser(User user) {
Expand Down

0 comments on commit be5d59f

Please sign in to comment.