|
@ -10,9 +10,6 @@ import java.util.List; |
|
|
import java.io.FileWriter; |
|
|
import java.io.FileWriter; |
|
|
import java.io.IOException; |
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
|
import java.security.MessageDigest; |
|
|
|
|
|
import java.security.NoSuchAlgorithmException; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.UUID; |
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
|
class CreateUser { |
|
|
class CreateUser { |
|
@ -29,7 +26,7 @@ class CreateUser { |
|
|
public CreateUser(String id, String name, String password, String birthday, String firstName, String surname) { |
|
|
public CreateUser(String id, String name, String password, String birthday, String firstName, String surname) { |
|
|
this.id = id; |
|
|
this.id = id; |
|
|
this.userName = name; |
|
|
this.userName = name; |
|
|
this.password = hashPassword(password); |
|
|
|
|
|
|
|
|
this.password = PasswordHasher.hashPassword(password);; |
|
|
this.birthday = birthday; |
|
|
this.birthday = birthday; |
|
|
this.firstName = firstName; |
|
|
this.firstName = firstName; |
|
|
this.surname = surname; |
|
|
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 |
|
|
// Function to save to JSON file, replace with database call later |
|
|
public void saveToJsonFile(String filename) { |
|
|
public void saveToJsonFile(String filename) { |
|
|
List<CreateUser> userList = readUserListFromJsonFile(filename); |
|
|
List<CreateUser> userList = readUserListFromJsonFile(filename); |
|
|