mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-27 20:57:35 +01:00
fix string concatenates performance
This commit is contained in:
parent
026d84427b
commit
221b32744c
@ -138,7 +138,7 @@ public class JsonCache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class PlayerDataDeserializer implements JsonDeserializer<DataFileCache> {
|
private static class PlayerDataDeserializer implements JsonDeserializer<DataFileCache> {
|
||||||
@Override
|
@Override
|
||||||
public DataFileCache deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
|
public DataFileCache deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
|
||||||
JsonObject jsonObject = jsonElement.getAsJsonObject();
|
JsonObject jsonObject = jsonElement.getAsJsonObject();
|
||||||
|
@ -156,7 +156,7 @@ public class AdminCommand implements CommandExecutor {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PlayerAuth auth;
|
PlayerAuth auth;
|
||||||
String message = "[AuthMe] ";
|
StringBuilder message = new StringBuilder("[AuthMe] ");
|
||||||
try {
|
try {
|
||||||
auth = plugin.database.getAuth(arguments[1].toLowerCase());
|
auth = plugin.database.getAuth(arguments[1].toLowerCase());
|
||||||
} catch (NullPointerException npe) {
|
} catch (NullPointerException npe) {
|
||||||
@ -179,25 +179,24 @@ public class AdminCommand implements CommandExecutor {
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
for (String account : accountList) {
|
for (String account : accountList) {
|
||||||
i++;
|
i++;
|
||||||
message = message + account;
|
message.append(account);
|
||||||
if (i != accountList.size()) {
|
if (i != accountList.size()) {
|
||||||
message = message + ", ";
|
message.append(", ");
|
||||||
} else {
|
} else {
|
||||||
message = message + ".";
|
message.append(".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sender.sendMessage("[AuthMe] " + arguments[1] + " has " + String.valueOf(accountList.size()) + " accounts");
|
sender.sendMessage("[AuthMe] " + arguments[1] + " has " + String.valueOf(accountList.size()) + " accounts");
|
||||||
sender.sendMessage(message);
|
sender.sendMessage(message.toString());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
final String[] arguments = args;
|
final String[] arguments = args;
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
String message = "[AuthMe] ";
|
StringBuilder message = new StringBuilder("[AuthMe] ");
|
||||||
if (arguments[1] == null) {
|
if (arguments[1] == null) {
|
||||||
sender.sendMessage("[AuthMe] Please put a valid IP");
|
sender.sendMessage("[AuthMe] Please put a valid IP");
|
||||||
return;
|
return;
|
||||||
@ -214,15 +213,15 @@ public class AdminCommand implements CommandExecutor {
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
for (String account : accountList) {
|
for (String account : accountList) {
|
||||||
i++;
|
i++;
|
||||||
message = message + account;
|
message.append(account);
|
||||||
if (i != accountList.size()) {
|
if (i != accountList.size()) {
|
||||||
message = message + ", ";
|
message.append(", ");
|
||||||
} else {
|
} else {
|
||||||
message = message + ".";
|
message.append(".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sender.sendMessage("[AuthMe] " + arguments[1] + " has " + String.valueOf(accountList.size()) + " accounts");
|
sender.sendMessage("[AuthMe] " + arguments[1] + " has " + String.valueOf(accountList.size()) + " accounts");
|
||||||
sender.sendMessage(message);
|
sender.sendMessage(message.toString());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
|
@ -1,15 +1,8 @@
|
|||||||
package fr.xephi.authme.process.login;
|
package fr.xephi.authme.process.login;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import fr.xephi.authme.Utils;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
|
import fr.xephi.authme.Utils;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||||
@ -21,6 +14,12 @@ import fr.xephi.authme.security.RandomString;
|
|||||||
import fr.xephi.authme.settings.Messages;
|
import fr.xephi.authme.settings.Messages;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.task.MessageTask;
|
import fr.xephi.authme.task.MessageTask;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class AsyncronousLogin {
|
public class AsyncronousLogin {
|
||||||
|
|
||||||
@ -64,13 +63,9 @@ public class AsyncronousLogin {
|
|||||||
player.sendMessage(s.replace("THE_CAPTCHA", plugin.cap.get(name)).replace("<theCaptcha>", plugin.cap.get(name)));
|
player.sendMessage(s.replace("THE_CAPTCHA", plugin.cap.get(name)).replace("<theCaptcha>", plugin.cap.get(name)));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else
|
} else if (plugin.captcha.containsKey(name) && plugin.captcha.get(name) >= Settings.maxLoginTry) {
|
||||||
if (plugin.captcha.containsKey(name) && plugin.captcha.get(name) >= Settings.maxLoginTry) {
|
|
||||||
try {
|
|
||||||
plugin.captcha.remove(name);
|
plugin.captcha.remove(name);
|
||||||
plugin.cap.remove(name);
|
plugin.cap.remove(name);
|
||||||
} catch (NullPointerException npe) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -198,7 +193,6 @@ public class AsyncronousLogin {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
m.send(player, "wrong_pwd");
|
m.send(player, "wrong_pwd");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ConsoleLogger.showError("Player " + name + " wasn't online during login process, aborted... ");
|
ConsoleLogger.showError("Player " + name + " wasn't online during login process, aborted... ");
|
||||||
@ -221,17 +215,17 @@ public class AsyncronousLogin {
|
|||||||
if (auths.size() == 1) {
|
if (auths.size() == 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String message = "[AuthMe] ";
|
StringBuilder message = new StringBuilder("[AuthMe] ");
|
||||||
// String uuidaccounts =
|
// String uuidaccounts =
|
||||||
// "[AuthMe] PlayerNames has %size% links to this UUID : ";
|
// "[AuthMe] PlayerNames has %size% links to this UUID : ";
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (String account : auths) {
|
for (String account : auths) {
|
||||||
i++;
|
i++;
|
||||||
message = message + account;
|
message.append(account);
|
||||||
if (i != auths.size()) {
|
if (i != auths.size()) {
|
||||||
message = message + ", ";
|
message.append(", ");
|
||||||
} else {
|
} else {
|
||||||
message = message + ".";
|
message.append(".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@ -243,7 +237,7 @@ public class AsyncronousLogin {
|
|||||||
for (Player player : Utils.getOnlinePlayers()) {
|
for (Player player : Utils.getOnlinePlayers()) {
|
||||||
if (plugin.authmePermissible(player, "authme.seeOtherAccounts")) {
|
if (plugin.authmePermissible(player, "authme.seeOtherAccounts")) {
|
||||||
player.sendMessage("[AuthMe] The player " + auth.getNickname() + " has " + auths.size() + " accounts");
|
player.sendMessage("[AuthMe] The player " + auth.getNickname() + " has " + auths.size() + " accounts");
|
||||||
player.sendMessage(message);
|
player.sendMessage(message.toString());
|
||||||
// player.sendMessage(uuidaccounts.replace("%size%",
|
// player.sendMessage(uuidaccounts.replace("%size%",
|
||||||
// ""+uuidlist.size()));
|
// ""+uuidlist.size()));
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ import java.security.MessageDigest;
|
|||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author stefano
|
* @author stefano
|
||||||
*/
|
*/
|
||||||
public class PHPBB implements EncryptionMethod {
|
public class PHPBB implements EncryptionMethod {
|
||||||
@ -20,19 +19,16 @@ public class PHPBB implements EncryptionMethod {
|
|||||||
|
|
||||||
public String phpbb_hash(String password, String salt) {
|
public String phpbb_hash(String password, String salt) {
|
||||||
String random_state = salt;
|
String random_state = salt;
|
||||||
String random = "";
|
StringBuilder random = new StringBuilder();
|
||||||
int count = 6;
|
int count = 6;
|
||||||
if (random.length() < count) {
|
|
||||||
random = "";
|
|
||||||
for (int i = 0; i < count; i += 16) {
|
for (int i = 0; i < count; i += 16) {
|
||||||
random_state = md5(salt + random_state);
|
random_state = md5(salt + random_state);
|
||||||
random += pack(md5(random_state));
|
random.append(pack(md5(random_state)));
|
||||||
}
|
}
|
||||||
random = random.substring(0, count);
|
String hash = _hash_crypt_private(password, _hash_gensalt_private(random.substring(0, count), itoa64));
|
||||||
}
|
if (hash.length() == 34) {
|
||||||
String hash = _hash_crypt_private(password, _hash_gensalt_private(random, itoa64));
|
|
||||||
if (hash.length() == 34)
|
|
||||||
return hash;
|
return hash;
|
||||||
|
}
|
||||||
return md5(password);
|
return md5(password);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,7 +36,6 @@ public class PHPBB implements EncryptionMethod {
|
|||||||
return _hash_gensalt_private(input, itoa64, 6);
|
return _hash_gensalt_private(input, itoa64, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private String _hash_gensalt_private(String input, String itoa64,
|
private String _hash_gensalt_private(String input, String itoa64,
|
||||||
int iteration_count_log2) {
|
int iteration_count_log2) {
|
||||||
if (iteration_count_log2 < 4 || iteration_count_log2 > 31) {
|
if (iteration_count_log2 < 4 || iteration_count_log2 > 31) {
|
||||||
@ -109,9 +104,7 @@ public class PHPBB implements EncryptionMethod {
|
|||||||
MessageDigest md5er = MessageDigest.getInstance("MD5");
|
MessageDigest md5er = MessageDigest.getInstance("MD5");
|
||||||
byte[] hash = md5er.digest(bytes);
|
byte[] hash = md5er.digest(bytes);
|
||||||
return bytes2hex(hash);
|
return bytes2hex(hash);
|
||||||
} catch (GeneralSecurityException e) {
|
} catch (GeneralSecurityException | UnsupportedEncodingException e) {
|
||||||
throw new RuntimeException(e);
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -126,9 +119,9 @@ public class PHPBB implements EncryptionMethod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static String bytes2hex(byte[] bytes) {
|
private static String bytes2hex(byte[] bytes) {
|
||||||
StringBuffer r = new StringBuffer(32);
|
StringBuilder r = new StringBuilder(32);
|
||||||
for (int i = 0; i < bytes.length; i++) {
|
for (byte b : bytes) {
|
||||||
String x = Integer.toHexString(bytes[i] & 0xff);
|
String x = Integer.toHexString(b & 0xff);
|
||||||
if (x.length() < 2)
|
if (x.length() < 2)
|
||||||
r.append("0");
|
r.append("0");
|
||||||
r.append(x);
|
r.append(x);
|
||||||
@ -137,7 +130,7 @@ public class PHPBB implements EncryptionMethod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static String pack(String hex) {
|
static String pack(String hex) {
|
||||||
StringBuffer buf = new StringBuffer();
|
StringBuilder buf = new StringBuilder();
|
||||||
for (int i = 0; i < hex.length(); i += 2) {
|
for (int i = 0; i < hex.length(); i += 2) {
|
||||||
char c1 = hex.charAt(i);
|
char c1 = hex.charAt(i);
|
||||||
char c2 = hex.charAt(i + 1);
|
char c2 = hex.charAt(i + 1);
|
||||||
|
@ -8,13 +8,12 @@ import java.util.Arrays;
|
|||||||
|
|
||||||
public class WORDPRESS implements EncryptionMethod {
|
public class WORDPRESS implements EncryptionMethod {
|
||||||
|
|
||||||
private static String itoa64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
private static final String itoa64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||||
private int iterationCountLog2 = 8;
|
|
||||||
private SecureRandom randomGen = new SecureRandom();
|
private SecureRandom randomGen = new SecureRandom();
|
||||||
|
|
||||||
private String encode64(byte[] src, int count) {
|
private String encode64(byte[] src, int count) {
|
||||||
int i, value;
|
int i, value;
|
||||||
String output = "";
|
StringBuilder output = new StringBuilder();
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
||||||
if (src.length < count) {
|
if (src.length < count) {
|
||||||
@ -26,24 +25,24 @@ public class WORDPRESS implements EncryptionMethod {
|
|||||||
do {
|
do {
|
||||||
value = src[i] + (src[i] < 0 ? 256 : 0);
|
value = src[i] + (src[i] < 0 ? 256 : 0);
|
||||||
++i;
|
++i;
|
||||||
output += itoa64.charAt(value & 63);
|
output.append(itoa64.charAt(value & 63));
|
||||||
if (i < count) {
|
if (i < count) {
|
||||||
value |= (src[i] + (src[i] < 0 ? 256 : 0)) << 8;
|
value |= (src[i] + (src[i] < 0 ? 256 : 0)) << 8;
|
||||||
}
|
}
|
||||||
output += itoa64.charAt((value >> 6) & 63);
|
output.append(itoa64.charAt((value >> 6) & 63));
|
||||||
if (i++ >= count) {
|
if (i++ >= count) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (i < count) {
|
if (i < count) {
|
||||||
value |= (src[i] + (src[i] < 0 ? 256 : 0)) << 16;
|
value |= (src[i] + (src[i] < 0 ? 256 : 0)) << 16;
|
||||||
}
|
}
|
||||||
output += itoa64.charAt((value >> 12) & 63);
|
output.append(itoa64.charAt((value >> 12) & 63));
|
||||||
if (i++ >= count) {
|
if (i++ >= count) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
output += itoa64.charAt((value >> 18) & 63);
|
output.append(itoa64.charAt((value >> 18) & 63));
|
||||||
} while (i < count);
|
} while (i < count);
|
||||||
return output;
|
return output.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String crypt(String password, String setting) {
|
private String crypt(String password, String setting) {
|
||||||
@ -86,7 +85,8 @@ public class WORDPRESS implements EncryptionMethod {
|
|||||||
|
|
||||||
private String gensaltPrivate(byte[] input) {
|
private String gensaltPrivate(byte[] input) {
|
||||||
String output = "$P$";
|
String output = "$P$";
|
||||||
output += itoa64.charAt(Math.min(this.iterationCountLog2 + 5, 30));
|
int iterationCountLog2 = 8;
|
||||||
|
output += itoa64.charAt(Math.min(iterationCountLog2 + 5, 30));
|
||||||
output += encode64(input, 6);
|
output += encode64(input, 6);
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user