generated from mate-academy/jv-homework-template
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a4b760c
commit e79bffa
Showing
2 changed files
with
6 additions
and
6 deletions.
There are no files selected for viewing
8 changes: 3 additions & 5 deletions
8
src/main/java/core/basesyntax/PasswordValidationException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
package core.basesyntax; | ||
|
||
public class PasswordValidationException extends Exception { | ||
PasswordValidationException() { | ||
super(); | ||
} | ||
import java.io.IOException; | ||
|
||
PasswordValidationException(String message) { | ||
public class PasswordValidationException extends IOException { | ||
public PasswordValidationException(String message) { | ||
super(message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
package core.basesyntax; | ||
|
||
public class PasswordValidator { | ||
private static final String ERROR_MESSAGE = "Wrong passwords"; | ||
|
||
public void validate(String password, String repeatPassword) | ||
throws PasswordValidationException { | ||
if (((password == null && repeatPassword == null) || password.length() == 0) | ||
|| (password.equals(repeatPassword) && password.length() < 10) | ||
|| !password.equals(repeatPassword)) { | ||
throw new PasswordValidationException("Wrong passwords"); | ||
throw new PasswordValidationException(ERROR_MESSAGE); | ||
} | ||
} | ||
} |