Merge pull request #7 from exzork/development

fix registerhandler and bump version
This commit is contained in:
Muhammad Eko Prasetyo 2022-05-06 22:25:05 +07:00 committed by GitHub
commit f0594825bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 15 deletions

View File

@ -10,7 +10,7 @@ sourceCompatibility = 17
targetCompatibility = 17 targetCompatibility = 17
group 'me.exzork.gcauth' group 'me.exzork.gcauth'
version '2.1.2' version '2.1.3'
repositories { repositories {
mavenCentral() mavenCentral()

View File

@ -29,6 +29,7 @@ public class RegisterHandler implements HttpContextHandler {
if (registerAccount.password.equals(registerAccount.password_confirmation)) { if (registerAccount.password.equals(registerAccount.password_confirmation)) {
if (registerAccount.password.length() >= 8) { if (registerAccount.password.length() >= 8) {
String password = Authentication.generateHash(registerAccount.password); String password = Authentication.generateHash(registerAccount.password);
try{
Account account = Authentication.getAccountByUsernameAndPassword(registerAccount.username, ""); Account account = Authentication.getAccountByUsernameAndPassword(registerAccount.username, "");
if (account != null) { if (account != null) {
account.setPassword(password); account.setPassword(password);
@ -48,6 +49,11 @@ public class RegisterHandler implements HttpContextHandler {
authResponse.jwt = ""; authResponse.jwt = "";
} }
} }
}catch (Exception ignored){
authResponse.success = false;
authResponse.message = "UNKNOWN"; // ENG = "Username has already been taken by another user."
authResponse.jwt = "";
}
} else { } else {
authResponse.success = false; authResponse.success = false;
authResponse.message = "PASSWORD_INVALID"; // ENG = "Password must be at least 8 characters long" authResponse.message = "PASSWORD_INVALID"; // ENG = "Password must be at least 8 characters long"

View File

@ -16,6 +16,7 @@ public final class Authentication {
public static Account getAccountByUsernameAndPassword(String username, String password) { public static Account getAccountByUsernameAndPassword(String username, String password) {
Account account = DatabaseHelper.getAccountByName(username); Account account = DatabaseHelper.getAccountByName(username);
if (account == null) return null;
if(account.getPassword() != null && !account.getPassword().isEmpty()) { if(account.getPassword() != null && !account.getPassword().isEmpty()) {
if(!verifyPassword(password, account.getPassword())) account = null; if(!verifyPassword(password, account.getPassword())) account = null;
} }