Browse Source

Added some validation logic for the username and password

remotes/origin/feature/client/make-input-field-buttons-interactive
Richard Schmidt 11 months ago
parent
commit
b40578f83e
  1. 1
      src/main/java/ChatServer.java
  2. 13
      src/main/java/SignUp.java

1
src/main/java/ChatServer.java

@ -4,7 +4,6 @@ import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
public class ChatServer { public class ChatServer {
// haha
private ServerSocket serverSocket; private ServerSocket serverSocket;
public ChatServer(int port) { public ChatServer(int port) {

13
src/main/java/SignUp.java

@ -27,13 +27,20 @@ public class SignUp {
// Function to create user // Function to create user
public static SignUp createUser(String name, String password) { public static SignUp createUser(String name, String password) {
// add validation logic here
return new SignUp(name, password);
if (name == null || name.isEmpty()) {
throw new IllegalArgumentException("Username cannot be empty");
}
if (password == null || password.isEmpty()) {
throw new IllegalArgumentException("Password cannot be empty");
}
if (password.length() < 6) {
throw new IllegalArgumentException("Password must be at least 6 characters long");
} return new SignUp(name, password);
} }
public static void main(String[] args) { public static void main(String[] args) {
// Example // Example
SignUp user = createUser("JohnDoe", "password123");
SignUp user = createUser("TestUser", "TestPasswort");
// Example of accessing properties // Example of accessing properties
System.out.println("User Name: " + user.getName()); System.out.println("User Name: " + user.getName());

Loading…
Cancel
Save