Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add password validation servise #1371

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
package core.basesyntax;

import java.util.concurrent.ExecutionException;

class PasswordValidationException extends Exception {
PasswordValidationException(String message) {
super(message);
}
}
//write your code here
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;

import java.io.IOException;

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("Password and repeat password cannot be null");
}
if (password.length() < 10 || !password.equals(repeatPassword)) {
throw new PasswordValidationException("Wrong passwords");
}
}
}
9 changes: 9 additions & 0 deletions src/main/java/core/basesyntax/UserService.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
package core.basesyntax;

import java.io.IOException;

public class UserService {
public void registerUser(User user) {
//write your code here
try {
new PasswordValidator().validate(user.getPassword(), user.getRepeatPassword());
} catch (PasswordValidationException e) {
System.out.println("Your passwords are incorrect. Try again.");
}

saveUser(user);
}

public void saveUser(User user) {
Expand Down
Loading