mirror of
https://github.com/exzork/GCAuth.git
synced 2024-11-24 00:23:58 +00:00
update to support 1.1.1-dev
This commit is contained in:
parent
1a7305adf6
commit
2675177800
@ -10,14 +10,14 @@ sourceCompatibility = 17
|
||||
targetCompatibility = 17
|
||||
|
||||
group 'me.exzork.gcauth'
|
||||
version '2.1.3'
|
||||
version '2.1.4'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation files('lib/grasscutter-1.0.3-dev.jar')
|
||||
implementation files('lib/grasscutter-1.1.1-dev.jar')
|
||||
implementation 'org.springframework.security:spring-security-crypto:5.6.3'
|
||||
implementation 'commons-logging:commons-logging:1.2'
|
||||
implementation 'com.auth0:java-jwt:3.19.1'
|
||||
|
@ -1,5 +1,8 @@
|
||||
package me.exzork.gcauth;
|
||||
|
||||
import me.exzork.gcauth.utils.Authentication;
|
||||
|
||||
public final class Config {
|
||||
public String Hash = "BCRYPT";
|
||||
public String jwtSecret = Authentication.generateRandomString(32);
|
||||
}
|
||||
|
@ -3,9 +3,9 @@ package me.exzork.gcauth;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.net.proto.QueryCurrRegionHttpRspOuterClass;
|
||||
import emu.grasscutter.plugin.Plugin;
|
||||
import me.exzork.gcauth.handler.*;
|
||||
import me.exzork.gcauth.utils.Authentication;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
@ -32,8 +32,9 @@ public class GCAuth extends Plugin {
|
||||
loadConfig();
|
||||
if(Grasscutter.getDispatchServer().registerAuthHandler(new GCAuthAuthenticationHandler())) {
|
||||
Grasscutter.getLogger().info("[GCAuth] GCAuth Enabled!");
|
||||
|
||||
if(Grasscutter.getConfig().getDispatchOptions().AutomaticallyCreateAccounts) {
|
||||
config.jwtSecret = Authentication.generateRandomString(32);
|
||||
saveConfig();
|
||||
if(Grasscutter.getConfig().account.autoCreate) {
|
||||
Grasscutter.getLogger().warn("[GCAuth] GCAuth does not support automatic account creation. Please disable in the server's config.json or just ignore this warning.");
|
||||
}
|
||||
} else {
|
||||
@ -65,5 +66,6 @@ public class GCAuth extends Plugin {
|
||||
Grasscutter.getLogger().error("[GCAuth] Unable to save config file.");
|
||||
}
|
||||
}
|
||||
public static Config getConfig() {return config;}
|
||||
public static Config getConfigStatic() {return config;}
|
||||
public Config getConfig() {return config;}
|
||||
}
|
||||
|
@ -13,6 +13,9 @@ import java.util.HashMap;
|
||||
public final class Authentication {
|
||||
public static final HashMap<String,String> tokens = new HashMap<String,String>();
|
||||
private static Algorithm key = Algorithm.HMAC256(generateRandomString(32));
|
||||
public static Algorithm getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public static Account getAccountByUsernameAndPassword(String username, String password) {
|
||||
Account account = DatabaseHelper.getAccountByName(username);
|
||||
@ -55,7 +58,7 @@ public final class Authentication {
|
||||
}
|
||||
|
||||
public static String generateHash(String password) {
|
||||
return switch (GCAuth.getConfig().Hash.toLowerCase()) {
|
||||
return switch (GCAuth.getConfigStatic().Hash.toLowerCase()) {
|
||||
case "bcrypt" -> new BCryptPasswordEncoder().encode(password);
|
||||
case "scrypt" -> new SCryptPasswordEncoder().encode(password);
|
||||
default -> password;
|
||||
@ -63,7 +66,7 @@ public final class Authentication {
|
||||
}
|
||||
|
||||
private static boolean verifyPassword(String password, String hash) {
|
||||
return switch (GCAuth.getConfig().Hash.toLowerCase()) {
|
||||
return switch (GCAuth.getConfigStatic().Hash.toLowerCase()) {
|
||||
case "bcrypt" -> new BCryptPasswordEncoder().matches(password, hash);
|
||||
case "scrypt" -> new SCryptPasswordEncoder().matches(password, hash);
|
||||
default -> password.equals(hash);
|
||||
|
Loading…
Reference in New Issue
Block a user