Skip to content

Commit

Permalink
added PasswordValidator and exception methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ynazarets committed Jul 11, 2024
1 parent d716b8e commit 555ef03
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ public class PasswordValidationException extends Exception {
public PasswordValidationException(String message) {
super(message);
}

}
6 changes: 3 additions & 3 deletions src/main/java/core/basesyntax/PasswordValidator.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package core.basesyntax;

public class PasswordValidator {
public static final int MIN_VALUE_FOR_PASSWORD = 10;
public static final int MIN_PASSWORD_LENGTH = 10;

public void validate(String password, String repeatPassword)
throws PasswordValidationException {
if (password != repeatPassword || password.length() < MIN_VALUE_FOR_PASSWORD
|| password == null || repeatPassword == null) {
if (password == null || repeatPassword == null
|| !password.equals(repeatPassword) || password.length() < MIN_PASSWORD_LENGTH) {
throw new PasswordValidationException("Wrong passwords");
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/core/basesyntax/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public class UserService {
private PasswordValidator passwordValidator = new PasswordValidator();

public void registerUser(User user) throws PasswordValidationException {
public void registerUser(User user) {
try {
passwordValidator.validate(user.getPassword(), user.getRepeatPassword());
saveUser(user);
Expand Down

0 comments on commit 555ef03

Please sign in to comment.