From e9a81229533d92515b19a303a87df83e273ce55c Mon Sep 17 00:00:00 2001 From: Richard Schmidt Date: Fri, 9 Feb 2024 20:54:38 +0100 Subject: [PATCH 01/12] refactoring: createUser method in CreateUser --- src/main/java/CreateUser.java | 20 ++++++++++++---- user.json | 45 ----------------------------------- 2 files changed, 15 insertions(+), 50 deletions(-) diff --git a/src/main/java/CreateUser.java b/src/main/java/CreateUser.java index 5a84cf6..31b1749 100644 --- a/src/main/java/CreateUser.java +++ b/src/main/java/CreateUser.java @@ -94,15 +94,25 @@ class CreateUser { // Function to create user with validation public static CreateUser createUser(String id, String userName, String password, String birthday, String firstName, String surname) { - if (userName == null || userName.isEmpty()) { - throw new IllegalArgumentException("Username cannot be empty"); + validateUserName(userName); + validatePassword(password); + + return new CreateUser(id, userName, password, birthday, firstName, surname); + } + + private static void validateUserName(String userName) { + if (userName == null || userName.isEmpty()) { + throw new IllegalArgumentException("Username cannot be empty"); } + } + + private static void validatePassword(String password) { if (password == null || password.isEmpty()) { - throw new IllegalArgumentException("Password cannot be empty"); + throw new IllegalArgumentException("Password cannot be empty"); } if (password.length() < 6) { - throw new IllegalArgumentException("Password must be at least 6 characters long"); - } return new CreateUser(id, userName, password, birthday, firstName, surname); + throw new IllegalArgumentException("Password must be at least 6 characters long"); + } } // Function to hash the password using SHA-256 algorithm diff --git a/user.json b/user.json index d1ad3d8..32960f8 100644 --- a/user.json +++ b/user.json @@ -1,47 +1,2 @@ [ - { - "id": "d7ae19fe-4684-4d69-a73d-4cca612962a3", - "userName": "Test", - "password": "8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92", - "birthday": "", - "firstName": "", - "surname": "", - "stayLoggedIn": false - }, - { - "id": "2ec2c0c5-677c-4262-8958-fef98d11cc63", - "userName": "Test2", - "password": "8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92", - "birthday": "", - "firstName": "", - "surname": "", - "stayLoggedIn": false - }, - { - "id": "ccfcc294-48ad-49db-996f-d7c99a93bac9", - "userName": "testuser", - "password": "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8", - "birthday": "2000-01-01", - "firstName": "John", - "surname": "Doe", - "stayLoggedIn": false - }, - { - "id": "27ffc70f-dd76-4765-81e3-76fde9b618e5", - "userName": "testUser", - "password": "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8", - "birthday": "1990-01-01", - "firstName": "John", - "surname": "Doe", - "stayLoggedIn": false - }, - { - "id": "731fda82-6b51-4f3f-ae97-c9b01c9b4a1a", - "userName": "existinguser", - "password": "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8", - "birthday": "1990-01-01", - "firstName": "John", - "surname": "Doe", - "stayLoggedIn": false - } ] \ No newline at end of file From f24fb69051d6a739b95aa645356b552b4ed6322e Mon Sep 17 00:00:00 2001 From: Richard Schmidt Date: Fri, 9 Feb 2024 21:47:27 +0100 Subject: [PATCH 02/12] refactoring: stayLoggedInCheckbox listener in LoginGUI --- src/main/java/LoginGUI.java | 17 +++++++---------- user.json | 3 +-- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/main/java/LoginGUI.java b/src/main/java/LoginGUI.java index 6731ae7..a05d9ca 100644 --- a/src/main/java/LoginGUI.java +++ b/src/main/java/LoginGUI.java @@ -75,17 +75,14 @@ public class LoginGUI extends JFrame implements ActionListener { passwordField.addKeyListener(new EnterKeyListener()); - stayLoggedInCheckbox.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - boolean stayLoggedIn = stayLoggedInCheckbox.isSelected(); - String username = usernameField.getText(); - // Set stayLoggedIn to false if the checkbox is unchecked - if (!stayLoggedInCheckbox.isSelected()) { - stayLoggedIn = false; - } - updateStayLoggedIn(username, stayLoggedIn); + stayLoggedInCheckbox.addActionListener(e -> { + boolean stayLoggedIn = stayLoggedInCheckbox.isSelected(); + String username = usernameField.getText(); + // Set stayLoggedIn to false if the checkbox is unchecked + if (!stayLoggedInCheckbox.isSelected()) { + stayLoggedIn = false; } + updateStayLoggedIn(username, stayLoggedIn); }); } diff --git a/user.json b/user.json index 32960f8..0637a08 100644 --- a/user.json +++ b/user.json @@ -1,2 +1 @@ -[ -] \ No newline at end of file +[] \ No newline at end of file From 60a1fe794c249d8df596df1e5bfc179e7e105bd9 Mon Sep 17 00:00:00 2001 From: Richard Schmidt Date: Fri, 9 Feb 2024 21:55:08 +0100 Subject: [PATCH 03/12] refactoring: actionPerformed in SignUpGUI --- src/main/java/LoginGUI.java | 7 +++- src/main/java/SignUpGUI.java | 74 +++++++++++++++++++++++------------- user.json | 21 +++++++++- 3 files changed, 72 insertions(+), 30 deletions(-) diff --git a/src/main/java/LoginGUI.java b/src/main/java/LoginGUI.java index a05d9ca..1c4ef8f 100644 --- a/src/main/java/LoginGUI.java +++ b/src/main/java/LoginGUI.java @@ -9,7 +9,11 @@ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class LoginGUI extends JFrame implements ActionListener { - private JTextField usernameField; + /** + * + */ + private static final long serialVersionUID = 1L; + private JTextField usernameField; private JPasswordField passwordField; private JButton loginButton; private JCheckBox stayLoggedInCheckbox; @@ -78,7 +82,6 @@ public class LoginGUI extends JFrame implements ActionListener { stayLoggedInCheckbox.addActionListener(e -> { boolean stayLoggedIn = stayLoggedInCheckbox.isSelected(); String username = usernameField.getText(); - // Set stayLoggedIn to false if the checkbox is unchecked if (!stayLoggedInCheckbox.isSelected()) { stayLoggedIn = false; } diff --git a/src/main/java/SignUpGUI.java b/src/main/java/SignUpGUI.java index 696786b..70aa72f 100644 --- a/src/main/java/SignUpGUI.java +++ b/src/main/java/SignUpGUI.java @@ -96,35 +96,55 @@ public class SignUpGUI extends JFrame implements ActionListener { @Override public void actionPerformed(ActionEvent e) { - if (e.getSource() == signUpButton) { - String username = usernameField.getText(); - String password = passwordField.getText(); - String confirmPassword = confirmPasswordField.getText(); - String birthday = birthdayField.getText(); - String firstName = firstNameField.getText(); - String surname = surnameField.getText(); - - if (!password.equals(confirmPassword)) { - JOptionPane.showMessageDialog(this, "Passwords do not match!", "Sign Up Error", JOptionPane.ERROR_MESSAGE); - return; - } - - if (!isUsernameAvailable("user.json", username)) { - JOptionPane.showMessageDialog(this, "Username already exists!", "Sign Up Error", JOptionPane.ERROR_MESSAGE); - return; - } - - try { - UUID randomUUID = UUID.randomUUID(); - CreateUser user = CreateUser.createUser(randomUUID.toString(), username, password, birthday, firstName, surname); - user.saveToJsonFile("user.json"); - JOptionPane.showMessageDialog(this, "User signed up successfully!"); - dispose(); - } catch (IllegalArgumentException ex) { - JOptionPane.showMessageDialog(this, "Error: " + ex.getMessage(), "Sign Up Error", JOptionPane.ERROR_MESSAGE); - } + if (e.getSource() == signUpButton) { + signUpUser(); + } + } + + private void signUpUser() { + String username = usernameField.getText(); + String password = passwordField.getText(); + String confirmPassword = confirmPasswordField.getText(); + String birthday = birthdayField.getText(); + String firstName = firstNameField.getText(); + String surname = surnameField.getText(); + + if (!validatePasswordConfirmation(password, confirmPassword)) { + showErrorMessage("Passwords do not match!"); + return; + } + + if (!isUsernameAvailable("user.json", username)) { + showErrorMessage("Username already exists!"); + return; + } + + try { + createUserAndSave(username, password, birthday, firstName, surname); + showSuccessMessage("User signed up successfully!"); + dispose(); + } catch (IllegalArgumentException ex) { + showErrorMessage("Error: " + ex.getMessage()); } } + + private boolean validatePasswordConfirmation(String password, String confirmPassword) { + return password.equals(confirmPassword); + } + + private void showErrorMessage(String message) { + JOptionPane.showMessageDialog(this, message, "Sign Up Error", JOptionPane.ERROR_MESSAGE); + } + + private void showSuccessMessage(String message) { + JOptionPane.showMessageDialog(this, message); + } + + private void createUserAndSave(String username, String password, String birthday, String firstName, String surname) { + UUID randomUUID = UUID.randomUUID(); + CreateUser user = CreateUser.createUser(randomUUID.toString(), username, password, birthday, firstName, surname); + user.saveToJsonFile("user.json"); + } // Function to check if the input username doesn't already exist in the JSON file private boolean isUsernameAvailable(String filename, String username) { diff --git a/user.json b/user.json index 0637a08..cfc325c 100644 --- a/user.json +++ b/user.json @@ -1 +1,20 @@ -[] \ No newline at end of file +[ + { + "id": "e365e96f-6c6c-48e5-96e0-7b5e058e7198", + "userName": "existinguser", + "password": "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8", + "birthday": "1990-01-01", + "firstName": "John", + "surname": "Doe", + "stayLoggedIn": false + }, + { + "id": "61ef4208-9077-42c4-983f-f1e234f7e5f4", + "userName": "testUser", + "password": "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8", + "birthday": "1990-01-01", + "firstName": "John", + "surname": "Doe", + "stayLoggedIn": false + } +] \ No newline at end of file From 4391c0ee342fce1e6c1620dee128d9c5afa98a93 Mon Sep 17 00:00:00 2001 From: Richard Schmidt Date: Fri, 9 Feb 2024 21:57:16 +0100 Subject: [PATCH 04/12] refactoring: isUsernameAvailable in SignUpGUI --- src/main/java/SignUpGUI.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/main/java/SignUpGUI.java b/src/main/java/SignUpGUI.java index 70aa72f..faa360d 100644 --- a/src/main/java/SignUpGUI.java +++ b/src/main/java/SignUpGUI.java @@ -149,14 +149,7 @@ public class SignUpGUI extends JFrame implements ActionListener { // Function to check if the input username doesn't already exist in the JSON file private boolean isUsernameAvailable(String filename, String username) { List userList = CreateUser.readUserListFromJsonFile(filename); - if (userList != null) { - for (CreateUser user : userList) { - if (user.getUserName().equals(username)) { - return false; - } - } - } - return true; + return userList == null || userList.stream().noneMatch(user -> user.getUserName().equals(username)); } public static void main(String[] args) { From 85d6d2a0d3da52a971b26ece16375348a923ed7a Mon Sep 17 00:00:00 2001 From: Richard Schmidt Date: Fri, 9 Feb 2024 22:07:36 +0100 Subject: [PATCH 05/12] refactoring: moved the password hashing into own class PasswordHasher.java --- src/main/java/CreateUser.java | 23 +---------------------- src/main/java/PasswordHasher.java | 21 +++++++++++++++++++++ src/main/java/SignUpGUI.java | 4 ++++ user.json | 21 +-------------------- 4 files changed, 27 insertions(+), 42 deletions(-) create mode 100644 src/main/java/PasswordHasher.java diff --git a/src/main/java/CreateUser.java b/src/main/java/CreateUser.java index 31b1749..01085c9 100644 --- a/src/main/java/CreateUser.java +++ b/src/main/java/CreateUser.java @@ -10,9 +10,6 @@ import java.util.List; import java.io.FileWriter; import java.io.IOException; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - import java.util.UUID; class CreateUser { @@ -29,7 +26,7 @@ class CreateUser { public CreateUser(String id, String name, String password, String birthday, String firstName, String surname) { this.id = id; this.userName = name; - this.password = hashPassword(password); + this.password = PasswordHasher.hashPassword(password);; this.birthday = birthday; this.firstName = firstName; this.surname = surname; @@ -115,24 +112,6 @@ class CreateUser { } } - // Function to hash the password using SHA-256 algorithm - private String hashPassword(String password) { - try { - MessageDigest digest = MessageDigest.getInstance("SHA-256"); - byte[] hash = digest.digest(password.getBytes()); - StringBuilder hexString = new StringBuilder(); - for (byte b : hash) { - String hex = Integer.toHexString(0xff & b); - if (hex.length() == 1) hexString.append('0'); - hexString.append(hex); - } - return hexString.toString(); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - return null; - } - } - // Function to save to JSON file, replace with database call later public void saveToJsonFile(String filename) { List userList = readUserListFromJsonFile(filename); diff --git a/src/main/java/PasswordHasher.java b/src/main/java/PasswordHasher.java new file mode 100644 index 0000000..14a1137 --- /dev/null +++ b/src/main/java/PasswordHasher.java @@ -0,0 +1,21 @@ +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +public class PasswordHasher { + public static String hashPassword(String password) { + try { + MessageDigest digest = MessageDigest.getInstance("SHA-256"); + byte[] hash = digest.digest(password.getBytes()); + StringBuilder hexString = new StringBuilder(); + for (byte b : hash) { + String hex = Integer.toHexString(0xff & b); + if (hex.length() == 1) hexString.append('0'); + hexString.append(hex); + } + return hexString.toString(); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + return null; + } + } +} \ No newline at end of file diff --git a/src/main/java/SignUpGUI.java b/src/main/java/SignUpGUI.java index faa360d..b9f7b1c 100644 --- a/src/main/java/SignUpGUI.java +++ b/src/main/java/SignUpGUI.java @@ -5,6 +5,10 @@ import java.util.List; import java.util.UUID; public class SignUpGUI extends JFrame implements ActionListener { + /** + * + */ + private static final long serialVersionUID = 1L; private JTextField usernameField, passwordField, confirmPasswordField, birthdayField, firstNameField, surnameField; private JButton signUpButton; diff --git a/user.json b/user.json index cfc325c..0637a08 100644 --- a/user.json +++ b/user.json @@ -1,20 +1 @@ -[ - { - "id": "e365e96f-6c6c-48e5-96e0-7b5e058e7198", - "userName": "existinguser", - "password": "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8", - "birthday": "1990-01-01", - "firstName": "John", - "surname": "Doe", - "stayLoggedIn": false - }, - { - "id": "61ef4208-9077-42c4-983f-f1e234f7e5f4", - "userName": "testUser", - "password": "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8", - "birthday": "1990-01-01", - "firstName": "John", - "surname": "Doe", - "stayLoggedIn": false - } -] \ No newline at end of file +[] \ No newline at end of file From 5e0110a8f12727c74ede5b6861764e7727d45ba5 Mon Sep 17 00:00:00 2001 From: Richard Schmidt Date: Fri, 9 Feb 2024 22:10:59 +0100 Subject: [PATCH 06/12] refactoring: removed the hashing function in LoginGUI and replaced it with the PasswordHasher class --- src/main/java/CreateUser.java | 2 +- src/main/java/LoginGUI.java | 21 +-------------------- user.json | 12 +++++++++++- 3 files changed, 13 insertions(+), 22 deletions(-) diff --git a/src/main/java/CreateUser.java b/src/main/java/CreateUser.java index 01085c9..e3ce511 100644 --- a/src/main/java/CreateUser.java +++ b/src/main/java/CreateUser.java @@ -26,7 +26,7 @@ class CreateUser { public CreateUser(String id, String name, String password, String birthday, String firstName, String surname) { this.id = id; this.userName = name; - this.password = PasswordHasher.hashPassword(password);; + this.password = PasswordHasher.hashPassword(password); this.birthday = birthday; this.firstName = firstName; this.surname = surname; diff --git a/src/main/java/LoginGUI.java b/src/main/java/LoginGUI.java index 1c4ef8f..c1f61ec 100644 --- a/src/main/java/LoginGUI.java +++ b/src/main/java/LoginGUI.java @@ -123,7 +123,7 @@ public class LoginGUI extends JFrame implements ActionListener { if (userList != null) { for (CreateUser user : userList) { if (user.getUserName().equals(username)) { - String hashedPassword = hashPassword(password); + String hashedPassword = PasswordHasher.hashPassword(password); if (user.getPassword().equals(hashedPassword)) { return true; } @@ -133,25 +133,6 @@ public class LoginGUI extends JFrame implements ActionListener { return false; } - private String hashPassword(String password) { - try { - MessageDigest digest = MessageDigest.getInstance("SHA-256"); - byte[] hash = digest.digest(password.getBytes()); - StringBuilder hexString = new StringBuilder(); - for (byte b : hash) { - String hex = Integer.toHexString(0xff & b); - if (hex.length() == 1) { - hexString.append('0'); - } - hexString.append(hex); - } - return hexString.toString(); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - return null; - } - } - private class EnterKeyListener implements KeyListener { @Override public void keyTyped(KeyEvent e) {} diff --git a/user.json b/user.json index 0637a08..cd6dd0d 100644 --- a/user.json +++ b/user.json @@ -1 +1,11 @@ -[] \ No newline at end of file +[ + { + "id": "c99b1061-13b7-4fa8-b1ac-814e07db3ef4", + "userName": "Test", + "password": "8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92", + "birthday": "", + "firstName": "", + "surname": "", + "stayLoggedIn": false + } +] \ No newline at end of file From 3ae06c192fbefdaac4994a384d11986179faf374 Mon Sep 17 00:00:00 2001 From: Richard Schmidt Date: Fri, 9 Feb 2024 22:16:46 +0100 Subject: [PATCH 07/12] refactoring: removed unused import from LoginGUI --- src/main/java/LoginGUI.java | 3 --- user.json | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/java/LoginGUI.java b/src/main/java/LoginGUI.java index c1f61ec..82f4ae4 100644 --- a/src/main/java/LoginGUI.java +++ b/src/main/java/LoginGUI.java @@ -5,9 +5,6 @@ import java.util.List; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - public class LoginGUI extends JFrame implements ActionListener { /** * diff --git a/user.json b/user.json index cd6dd0d..8242745 100644 --- a/user.json +++ b/user.json @@ -7,5 +7,23 @@ "firstName": "", "surname": "", "stayLoggedIn": false + }, + { + "id": "89de267d-8456-4393-9fab-a5ddb36c7686", + "userName": "existinguser", + "password": "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8", + "birthday": "1990-01-01", + "firstName": "John", + "surname": "Doe", + "stayLoggedIn": false + }, + { + "id": "43d45e81-3540-427f-8cb9-8f279d7a18d3", + "userName": "testUser", + "password": "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8", + "birthday": "1990-01-01", + "firstName": "John", + "surname": "Doe", + "stayLoggedIn": false } ] \ No newline at end of file From d03f7a27ca99330a4a4396d8f397419894a2a984 Mon Sep 17 00:00:00 2001 From: Richard Schmidt Date: Fri, 9 Feb 2024 22:17:48 +0100 Subject: [PATCH 08/12] refactoring: removed unused import from CreateUserTest --- src/test/java/CreateUserTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/CreateUserTest.java b/src/test/java/CreateUserTest.java index cc70da6..1120139 100644 --- a/src/test/java/CreateUserTest.java +++ b/src/test/java/CreateUserTest.java @@ -2,7 +2,6 @@ import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Test; import java.io.File; import java.util.List; -import static org.junit.jupiter.api.Assertions.*; class CreateUserTest { From 0178fc61d0e99dd9f0cbfe78f9ee219e7e26d838 Mon Sep 17 00:00:00 2001 From: Richard Schmidt Date: Fri, 9 Feb 2024 22:26:23 +0100 Subject: [PATCH 09/12] test_implemented PasswordHasherTest and fixed null password test failure for PasswordHasher --- src/main/java/PasswordHasher.java | 4 ++++ src/test/java/PasswordHasherTest.java | 27 ++++++++++++++++++++++++++ user.json | 28 +-------------------------- 3 files changed, 32 insertions(+), 27 deletions(-) create mode 100644 src/test/java/PasswordHasherTest.java diff --git a/src/main/java/PasswordHasher.java b/src/main/java/PasswordHasher.java index 14a1137..2ae5d8d 100644 --- a/src/main/java/PasswordHasher.java +++ b/src/main/java/PasswordHasher.java @@ -3,6 +3,10 @@ import java.security.NoSuchAlgorithmException; public class PasswordHasher { public static String hashPassword(String password) { + if (password == null) { + throw new IllegalArgumentException("Password cannot be null"); + } + try { MessageDigest digest = MessageDigest.getInstance("SHA-256"); byte[] hash = digest.digest(password.getBytes()); diff --git a/src/test/java/PasswordHasherTest.java b/src/test/java/PasswordHasherTest.java new file mode 100644 index 0000000..6177642 --- /dev/null +++ b/src/test/java/PasswordHasherTest.java @@ -0,0 +1,27 @@ +import org.junit.jupiter.api.Test; + +import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class PasswordHasherTest { + + @Test + void testHashPassword() { + String password = "password123"; + String hashedPassword = PasswordHasher.hashPassword(password); + + // Check that the hashed password is not null + assertEquals(64, hashedPassword.length()); + + // Test with an empty password + String emptyPassword = ""; + String hashedEmptyPassword = PasswordHasher.hashPassword(emptyPassword); + assertEquals(64, hashedEmptyPassword.length()); + + // Test with a null password + assertThrows(IllegalArgumentException.class, () -> { + PasswordHasher.hashPassword(null); + }); + } +} \ No newline at end of file diff --git a/user.json b/user.json index 8242745..c44dc44 100644 --- a/user.json +++ b/user.json @@ -1,29 +1,3 @@ [ - { - "id": "c99b1061-13b7-4fa8-b1ac-814e07db3ef4", - "userName": "Test", - "password": "8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92", - "birthday": "", - "firstName": "", - "surname": "", - "stayLoggedIn": false - }, - { - "id": "89de267d-8456-4393-9fab-a5ddb36c7686", - "userName": "existinguser", - "password": "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8", - "birthday": "1990-01-01", - "firstName": "John", - "surname": "Doe", - "stayLoggedIn": false - }, - { - "id": "43d45e81-3540-427f-8cb9-8f279d7a18d3", - "userName": "testUser", - "password": "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8", - "birthday": "1990-01-01", - "firstName": "John", - "surname": "Doe", - "stayLoggedIn": false - } + ] \ No newline at end of file From e815914b906d18897320444a90672d5d488de746 Mon Sep 17 00:00:00 2001 From: fdai7599 Date: Fri, 9 Feb 2024 21:27:36 +0000 Subject: [PATCH 10/12] Update README.md --- README.md | 96 +++++-------------------------------------------------- 1 file changed, 8 insertions(+), 88 deletions(-) diff --git a/README.md b/README.md index 8a88154..5df540f 100644 --- a/README.md +++ b/README.md @@ -1,92 +1,12 @@ # Java Chat +Projekt Informationen +Führe build-project.sh aus +Eventuell führt das Skript die Dateien in einer falschen Reihenfolge aus +Wichtig für JavaChat-Start...in dieser Reihenfolge ausführen: +1. Starte ChatServer-Klasse +2. Starte ChatClient-Klasse und verbinde mit ChatServer über dessen IP(falls Lokal auf gleichem Rechner, kann 127.0.0.1 verwendet werden) +3. Andere Clients im gleichen Netzwerk können sich über starten eines ChatClients über die IP des Servers ebenfalls mit dem Chat verbinden. -## Getting started - -To make it easy for you to get started with GitLab, here's a list of recommended next steps. - -Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! - -## Add your files - -- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files -- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command: - -``` -cd existing_repo -git remote add origin https://gitlab.cs.hs-fulda.de/fdai7332/java-chat.git -git branch -M main -git push -uf origin main -``` - -## Integrate with your tools - -- [ ] [Set up project integrations](https://gitlab.cs.hs-fulda.de/fdai7332/java-chat/-/settings/integrations) - -## Collaborate with your team - -- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) -- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) -- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) -- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) -- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html) - -## Test and Deploy - -Use the built-in continuous integration in GitLab. - -- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html) -- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) -- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) -- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) -- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) - -*** - -# Editing this README - -When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template. - -## Suggestions for a good README -Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. - -## Name -Choose a self-explaining name for your project. - -## Description -Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. - -## Badges -On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. - -## Visuals -Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. - -## Installation -Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. - -## Usage -Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. - -## Support -Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. - -## Roadmap -If you have ideas for releases in the future, it is a good idea to list them in the README. - -## Contributing -State if you are open to contributions and what your requirements are for accepting them. - -For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. - -You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. - -## Authors and acknowledgment -Show your appreciation to those who have contributed to the project. - -## License -For open source projects, say how it is licensed. - -## Project status -If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. +Zusatzklassen im Repository können einzeln ausgeführt werden From 084b105c06cde12eb61c7f28d8bfb8aff76d55e9 Mon Sep 17 00:00:00 2001 From: Richard Schmidt Date: Fri, 9 Feb 2024 22:31:09 +0100 Subject: [PATCH 11/12] refactoring: removed unused import in PasswordHasherTest --- src/test/java/PasswordHasherTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/PasswordHasherTest.java b/src/test/java/PasswordHasherTest.java index 6177642..4649017 100644 --- a/src/test/java/PasswordHasherTest.java +++ b/src/test/java/PasswordHasherTest.java @@ -2,7 +2,6 @@ import org.junit.jupiter.api.Test; import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; public class PasswordHasherTest { From 1fb0efd3e915c63dda7cdb92e4ba95c004e47b33 Mon Sep 17 00:00:00 2001 From: Richard Schmidt Date: Fri, 9 Feb 2024 22:48:43 +0100 Subject: [PATCH 12/12] added depencies in pom.xml --- notizen.txt | 1 + pom.xml | 7 +++++++ src/test/java/ChatGUITest.java | 3 ++- user.json | 19 ++++++++++++++++++- 4 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 notizen.txt diff --git a/notizen.txt b/notizen.txt new file mode 100644 index 0000000..b2fd9e1 --- /dev/null +++ b/notizen.txt @@ -0,0 +1 @@ +Äpfel & Birnen € \ No newline at end of file diff --git a/pom.xml b/pom.xml index 11c18f3..9457940 100644 --- a/pom.xml +++ b/pom.xml @@ -17,6 +17,13 @@ 4.13.2 test + + + org.junit.jupiter + junit-jupiter-api + 5.10.2 + test + diff --git a/src/test/java/ChatGUITest.java b/src/test/java/ChatGUITest.java index 1ef4f3f..0405000 100644 --- a/src/test/java/ChatGUITest.java +++ b/src/test/java/ChatGUITest.java @@ -1,3 +1,5 @@ +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -8,7 +10,6 @@ import java.text.SimpleDateFormat; import java.util.Date; import org.junit.Before; -import org.junit.Test; public class ChatGUITest { diff --git a/user.json b/user.json index c44dc44..107205c 100644 --- a/user.json +++ b/user.json @@ -1,3 +1,20 @@ [ - + { + "id": "20311680-1dbc-4a1d-af43-48462ab5dcef", + "userName": "existinguser", + "password": "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8", + "birthday": "1990-01-01", + "firstName": "John", + "surname": "Doe", + "stayLoggedIn": false + }, + { + "id": "aed49698-89cd-4712-920f-e30f23793f46", + "userName": "testUser", + "password": "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8", + "birthday": "1990-01-01", + "firstName": "John", + "surname": "Doe", + "stayLoggedIn": false + } ] \ No newline at end of file