diff --git a/Discord/src/main/java/com/baseband/bot/Main.java b/Discord/src/main/java/com/baseband/bot/Main.java index 50a9c8d..a73e212 100644 --- a/Discord/src/main/java/com/baseband/bot/Main.java +++ b/Discord/src/main/java/com/baseband/bot/Main.java @@ -143,7 +143,7 @@ public class Main extends ListenerAdapter { try { TCN tcn = new TCN(); - tcn.set("action", "create"); + tcn.set("action", "add"); tcn.set("authorisation", Hasher.sha512hex(password)); tcn.set("discord-id", user.getIdLong()); event.reply("Contacting server...").setEphemeral(true).queue(); @@ -212,7 +212,7 @@ public class Main extends ListenerAdapter { } case 400: { - event.reply("Error! I sent malformed data somehow.").setEphemeral(true).queue(); + event.reply("Error! I sent malformed data somehow.\n\nEither I am broken,\nor your password is too long.").setEphemeral(true).queue(); break; } diff --git a/Server/src/main/java/com/baseband/server/BotServiceHandler.java b/Server/src/main/java/com/baseband/server/BotServiceHandler.java index 3611411..2658046 100644 --- a/Server/src/main/java/com/baseband/server/BotServiceHandler.java +++ b/Server/src/main/java/com/baseband/server/BotServiceHandler.java @@ -8,6 +8,7 @@ import de.tudbut.tools.Hasher; import java.io.IOException; import java.net.Socket; +import java.nio.charset.StandardCharsets; import java.security.SecureRandom; public class BotServiceHandler { @@ -68,7 +69,7 @@ public class BotServiceHandler { TCN userToAdd = new TCN(); tcn.set("username", username); - tcn.set("password", BCrypt.withDefaults().hashToString(4, new String(SecureRandom.getSeed(64)).toCharArray())); + tcn.set("password", BCrypt.withDefaults().hashToString(4, new String(SecureRandom.getSeed(32), StandardCharsets.ISO_8859_1).toCharArray())); tcn.set("hardware-id", Hasher.sha512hex(new String(SecureRandom.getSeed(512)))); tcn.set("hardware-id-reset", true); tcn.set("disabled", false); @@ -92,8 +93,11 @@ public class BotServiceHandler { System.out.println("Bot processed " + action); Main.save(); - } catch (TCN.TCNException e) { + } catch (Exception e) { tos.writeInt(400); } + finally { + tos.getStream().close(); + } } }