Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Tonny-gif committed Oct 14, 2023
1 parent b4ce832 commit 9ba61eb
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
6 changes: 4 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
</properties>

<dependencies>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<version>4.13.2</version>
<scope>test</scope>
</dependency>

</dependencies>
<build>
<plugins>
Expand All @@ -41,7 +43,7 @@
</executions>
<configuration>
<configLocation>${maven.checkstyle.plugin.configLocation}</configLocation>
<encoding>UTF-8</encoding>

<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<linkXRef>false</linkXRef>
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/core/basesyntax/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package core.basesyntax;

public class Main {
public static void main(String[] args) {
User user = new User("hello", null, null);

UserService userService = new UserService();
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);
}
}
10 changes: 8 additions & 2 deletions src/main/java/core/basesyntax/PasswordValidator.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
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 && repeatPassword == null
|| password.length() < 10 && repeatPassword.length() < 10
|| !(password.equals(repeatPassword))) {
throw new PasswordValidationException("Wrong passwords");
}
}
}
9 changes: 8 additions & 1 deletion src/main/java/core/basesyntax/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

public class UserService {
public void registerUser(User user) {
//write your code here
PasswordValidator passwordValidator = new PasswordValidator();
try {
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 9ba61eb

Please sign in to comment.