Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 16 additions & 0 deletions src/main/java/core/basesyntax/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package core.basesyntax;

public class Main {
public static void main(String[] agr) {
UserService userService = new UserService();
User bob = new User("[email protected]", "1234567890", "1234567890");
User alice = new User("[email protected]", "1234567890", "0987654321");
User mark = new User("[email protected]", "1234", "1234");
User marie = new User("[email protected]", "1234567890", null);
User[] users = new User[]{bob, alice, mark, marie};

for (User user : users) {
userService.registerUser(user);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
package core.basesyntax;

//write your code here
public class PasswordValidationException extends Exception {
public PasswordValidationException(String message) {
super(message);
}
}
8 changes: 6 additions & 2 deletions src/main/java/core/basesyntax/PasswordValidator.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package core.basesyntax;

public class PasswordValidator {
public void validate(String password, String repeatPassword) {
//write your code here
public void validate(String password, String repeatPassword)
throws PasswordValidationException {

if (password == null || password.length() < 10 || !password.equals(repeatPassword)) {
throw new PasswordValidationException("Wrong passwords");
}
}
}
10 changes: 9 additions & 1 deletion src/main/java/core/basesyntax/UserService.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
package core.basesyntax;

public class UserService {
private final PasswordValidator passwordValidator = new PasswordValidator();

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

public void saveUser(User user) {
Expand Down