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.
add checked exception for validation passwords
- Loading branch information
Showing
3 changed files
with
26 additions
and
1 deletion.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
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,3 +1,8 @@ | ||
package core.basesyntax; | ||
|
||
//write your code here | ||
class PasswordValidationException extends Exception { | ||
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,7 +1,18 @@ | ||
package core.basesyntax; | ||
|
||
public class PasswordValidator { | ||
public void validate(String password, String repeatPassword) { | ||
public void validate(String password, String repeatPassword) | ||
throws PasswordValidationException { | ||
PasswordValidationException exception = new PasswordValidationException("Wrong passwords"); | ||
//write your code here | ||
if (password == null || repeatPassword == null) { | ||
throw exception; | ||
} | ||
if (password.length() < 10 && repeatPassword.length() < 10) { | ||
throw exception; | ||
} | ||
if (!password.equals(repeatPassword)) { | ||
throw exception; | ||
} | ||
} | ||
} |
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