From 061f70c376e42eb75bf5274389ce7f357a520fb2 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Wed, 4 May 2022 14:41:25 +0800 Subject: [PATCH] Fix the existing users can't register --- .../gcauth/handler/RegisterHandler.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/java/me/exzork/gcauth/handler/RegisterHandler.java b/src/main/java/me/exzork/gcauth/handler/RegisterHandler.java index 2949baa..382ee32 100644 --- a/src/main/java/me/exzork/gcauth/handler/RegisterHandler.java +++ b/src/main/java/me/exzork/gcauth/handler/RegisterHandler.java @@ -30,15 +30,25 @@ 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 = 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 { + Account account = Authentication.getAccountByUsernameAndPassword(registerAccount.username, ""); + if (account != null) { + String newPassword = Authentication.generateHash(password); + account.setPassword(newPassword); + 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 = ""; + } } } else { authResponse.success = false;