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