diff --git a/build.gradle b/build.gradle index 29533d7..6ff1831 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ sourceCompatibility = 17 targetCompatibility = 17 group 'me.exzork.gcauth' -version '2.1.2' +version '2.1.3' repositories { mavenCentral() diff --git a/src/main/java/me/exzork/gcauth/handler/RegisterHandler.java b/src/main/java/me/exzork/gcauth/handler/RegisterHandler.java index 39e6a04..bbe743e 100644 --- a/src/main/java/me/exzork/gcauth/handler/RegisterHandler.java +++ b/src/main/java/me/exzork/gcauth/handler/RegisterHandler.java @@ -29,24 +29,30 @@ public class RegisterHandler implements HttpContextHandler { if (registerAccount.password.equals(registerAccount.password_confirmation)) { if (registerAccount.password.length() >= 8) { String password = Authentication.generateHash(registerAccount.password); - Account account = Authentication.getAccountByUsernameAndPassword(registerAccount.username, ""); - if (account != null) { - account.setPassword(password); - account.save(); - authResponse.success = true; - authResponse.message = ""; - authResponse.jwt = ""; - } else { - account = DatabaseHelper.createAccountWithPassword(registerAccount.username, password); - if (account == null) { - authResponse.success = false; - authResponse.message = "USERNAME_TAKEN"; // ENG = "Username has already been taken by another user." - authResponse.jwt = ""; - } else { + try{ + Account account = Authentication.getAccountByUsernameAndPassword(registerAccount.username, ""); + if (account != null) { + account.setPassword(password); + account.save(); authResponse.success = true; authResponse.message = ""; authResponse.jwt = ""; + } else { + account = DatabaseHelper.createAccountWithPassword(registerAccount.username, password); + if (account == null) { + authResponse.success = false; + authResponse.message = "USERNAME_TAKEN"; // ENG = "Username has already been taken by another user." + authResponse.jwt = ""; + } else { + authResponse.success = true; + authResponse.message = ""; + authResponse.jwt = ""; + } } + }catch (Exception ignored){ + authResponse.success = false; + authResponse.message = "UNKNOWN"; // ENG = "Username has already been taken by another user." + authResponse.jwt = ""; } } else { authResponse.success = false; diff --git a/src/main/java/me/exzork/gcauth/utils/Authentication.java b/src/main/java/me/exzork/gcauth/utils/Authentication.java index 9a397a2..b55c4c2 100644 --- a/src/main/java/me/exzork/gcauth/utils/Authentication.java +++ b/src/main/java/me/exzork/gcauth/utils/Authentication.java @@ -16,6 +16,7 @@ public final class Authentication { public static Account getAccountByUsernameAndPassword(String username, String password) { Account account = DatabaseHelper.getAccountByName(username); + if (account == null) return null; if(account.getPassword() != null && !account.getPassword().isEmpty()) { if(!verifyPassword(password, account.getPassword())) account = null; }