Skip to content

Commit

Permalink
Modified PasswordValidationException.java, PasswordValidatior.java, U…
Browse files Browse the repository at this point in the history
…serService.java
  • Loading branch information
Danila2006 committed Nov 13, 2024
1 parent 223a4a7 commit 0fa0ba4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
package core.basesyntax;

//write your code here
public class PasswordValidationException extends Exception {
public PasswordValidationException(String message) {
super(message);
}
}
11 changes: 10 additions & 1 deletion src/main/java/core/basesyntax/PasswordValidator.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
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 || repeatPassword == null) {
throw new PasswordValidationException("Wrong passwords");
}

if (!password.equals(repeatPassword) || password.length() < 10
|| repeatPassword.length() < 10) {
throw new PasswordValidationException("Wrong passwords");
}
}
}
8 changes: 8 additions & 0 deletions src/main/java/core/basesyntax/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
public class UserService {
public void registerUser(User user) {
//write your code here
try {
PasswordValidator passwordValidator = new PasswordValidator();
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 0fa0ba4

Please sign in to comment.