Skip to content

Commit

Permalink
fix registerhandler and bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
exzork committed May 6, 2022
1 parent d08aba1 commit 1a7305a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ sourceCompatibility = 17
targetCompatibility = 17

group 'me.exzork.gcauth'
version '2.1.2'
version '2.1.3'

repositories {
mavenCentral()
Expand Down
34 changes: 20 additions & 14 deletions src/main/java/me/exzork/gcauth/handler/RegisterHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,30 @@ public void handle(Request request, Response response) throws IOException {
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;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/me/exzork/gcauth/utils/Authentication.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 1a7305a

Please # to comment.