antibot = new ArrayList<>();
/**
* Constructor for AuthMePlayerListener.
+ *
* @param plugin AuthMe
*/
public AuthMePlayerListener(AuthMe plugin) {
@@ -73,6 +55,7 @@ public class AuthMePlayerListener implements Listener {
/**
* Method handleChat.
+ *
* @param event AsyncPlayerChatEvent
*/
private void handleChat(AsyncPlayerChatEvent event) {
@@ -99,6 +82,7 @@ public class AuthMePlayerListener implements Listener {
/**
* Method onPlayerCommandPreprocess.
+ *
* @param event PlayerCommandPreprocessEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
@@ -115,6 +99,7 @@ public class AuthMePlayerListener implements Listener {
/**
* Method onPlayerNormalChat.
+ *
* @param event AsyncPlayerChatEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
@@ -124,6 +109,7 @@ public class AuthMePlayerListener implements Listener {
/**
* Method onPlayerHighChat.
+ *
* @param event AsyncPlayerChatEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
@@ -133,6 +119,7 @@ public class AuthMePlayerListener implements Listener {
/**
* Method onPlayerChat.
+ *
* @param event AsyncPlayerChatEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
@@ -142,6 +129,7 @@ public class AuthMePlayerListener implements Listener {
/**
* Method onPlayerHighestChat.
+ *
* @param event AsyncPlayerChatEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
@@ -151,6 +139,7 @@ public class AuthMePlayerListener implements Listener {
/**
* Method onPlayerEarlyChat.
+ *
* @param event AsyncPlayerChatEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
@@ -160,6 +149,7 @@ public class AuthMePlayerListener implements Listener {
/**
* Method onPlayerLowChat.
+ *
* @param event AsyncPlayerChatEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
@@ -169,6 +159,7 @@ public class AuthMePlayerListener implements Listener {
/**
* Method onPlayerMove.
+ *
* @param event PlayerMoveEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
@@ -207,10 +198,11 @@ public class AuthMePlayerListener implements Listener {
/**
* Method checkAntiBotMod.
+ *
* @param player Player
*/
private void checkAntiBotMod(final Player player) {
- if (plugin.delayedAntiBot || plugin.antibotMod)
+ if (plugin.delayedAntiBot || plugin.antiBotMod)
return;
if (plugin.getPermissionsManager().hasPermission(player, "authme.bypassantibot"))
return;
@@ -222,7 +214,7 @@ public class AuthMePlayerListener implements Listener {
@Override
public void run() {
- if (plugin.antibotMod) {
+ if (plugin.antiBotMod) {
plugin.switchAntiBotMod(false);
antibot.clear();
for (String s : m.send("antibot_auto_disabled"))
@@ -244,6 +236,7 @@ public class AuthMePlayerListener implements Listener {
/**
* Method onPlayerJoin.
+ *
* @param event PlayerJoinEvent
*/
@EventHandler(priority = EventPriority.HIGHEST)
@@ -267,7 +260,7 @@ public class AuthMePlayerListener implements Listener {
@Override
public void run() {
if (delay)
- joinMessage.put(name, joinMsg);
+ joinMessage.put(name, joinMsg);
plugin.management.performJoin(player);
}
});
@@ -275,6 +268,7 @@ public class AuthMePlayerListener implements Listener {
/**
* Method onPreLogin.
+ *
* @param event AsyncPlayerPreLoginEvent
*/
@EventHandler(priority = EventPriority.HIGHEST)
@@ -306,6 +300,7 @@ public class AuthMePlayerListener implements Listener {
/**
* Method onPlayerLogin.
+ *
* @param event PlayerLoginEvent
*/
@EventHandler(priority = EventPriority.HIGHEST)
@@ -329,7 +324,7 @@ public class AuthMePlayerListener implements Listener {
boolean isAuthAvailable = plugin.database.isAuthAvailable(name);
if (!Settings.countriesBlacklist.isEmpty() && !isAuthAvailable && !permsMan.hasPermission(player, "authme.bypassantibot")) {
- String code = Utils.getCountryCode(event.getAddress().getHostAddress());
+ String code = GeoLiteAPI.getCountryCode(event.getAddress().getHostAddress());
if (((code == null) || Settings.countriesBlacklist.contains(code))) {
event.setKickMessage(m.send("country_banned")[0]);
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
@@ -337,7 +332,7 @@ public class AuthMePlayerListener implements Listener {
}
}
if (Settings.enableProtection && !Settings.countries.isEmpty() && !isAuthAvailable && !permsMan.hasPermission(player, "authme.bypassantibot")) {
- String code = Utils.getCountryCode(event.getAddress().getHostAddress());
+ String code = GeoLiteAPI.getCountryCode(event.getAddress().getHostAddress());
if (((code == null) || !Settings.countries.contains(code))) {
event.setKickMessage(m.send("country_banned")[0]);
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
@@ -429,6 +424,7 @@ public class AuthMePlayerListener implements Listener {
/**
* Method onPlayerQuit.
+ *
* @param event PlayerQuitEvent
*/
@EventHandler(priority = EventPriority.MONITOR)
@@ -448,6 +444,7 @@ public class AuthMePlayerListener implements Listener {
/**
* Method onPlayerKick.
+ *
* @param event PlayerKickEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
@@ -467,6 +464,7 @@ public class AuthMePlayerListener implements Listener {
/**
* Method onPlayerPickupItem.
+ *
* @param event PlayerPickupItemEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
@@ -478,6 +476,7 @@ public class AuthMePlayerListener implements Listener {
/**
* Method onPlayerInteract.
+ *
* @param event PlayerInteractEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
@@ -490,6 +489,7 @@ public class AuthMePlayerListener implements Listener {
/**
* Method onPlayerConsumeItem.
+ *
* @param event PlayerItemConsumeEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
@@ -501,6 +501,7 @@ public class AuthMePlayerListener implements Listener {
/**
* Method onPlayerInventoryOpen.
+ *
* @param event InventoryOpenEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
@@ -525,6 +526,7 @@ public class AuthMePlayerListener implements Listener {
/**
* Method onPlayerInventoryClick.
+ *
* @param event InventoryClickEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
@@ -540,6 +542,7 @@ public class AuthMePlayerListener implements Listener {
/**
* Method playerHitPlayerEvent.
+ *
* @param event EntityDamageByEntityEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
@@ -556,6 +559,7 @@ public class AuthMePlayerListener implements Listener {
/**
* Method onPlayerInteractEntity.
+ *
* @param event PlayerInteractEntityEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
@@ -568,6 +572,7 @@ public class AuthMePlayerListener implements Listener {
/**
* Method onPlayerDropItem.
+ *
* @param event PlayerDropItemEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
@@ -579,6 +584,7 @@ public class AuthMePlayerListener implements Listener {
/**
* Method onPlayerBedEnter.
+ *
* @param event PlayerBedEnterEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
@@ -590,6 +596,7 @@ public class AuthMePlayerListener implements Listener {
/**
* Method onSignChange.
+ *
* @param event SignChangeEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
@@ -601,6 +608,7 @@ public class AuthMePlayerListener implements Listener {
/**
* Method onPlayerRespawn.
+ *
* @param event PlayerRespawnEvent
*/
@EventHandler(priority = EventPriority.HIGHEST)
@@ -621,6 +629,7 @@ public class AuthMePlayerListener implements Listener {
/**
* Method onPlayerGameModeChange.
+ *
* @param event PlayerGameModeChangeEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
@@ -643,6 +652,7 @@ public class AuthMePlayerListener implements Listener {
/**
* Method onPlayerShear.
+ *
* @param event PlayerShearEntityEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
@@ -655,6 +665,7 @@ public class AuthMePlayerListener implements Listener {
/**
* Method onPlayerFish.
+ *
* @param event PlayerFishEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
diff --git a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener16.java b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener16.java
index 0f7a47b60..0dd34daec 100644
--- a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener16.java
+++ b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener16.java
@@ -1,14 +1,13 @@
package fr.xephi.authme.listener;
+import fr.xephi.authme.AuthMe;
+import fr.xephi.authme.util.Utils;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerEditBookEvent;
-import fr.xephi.authme.AuthMe;
-import fr.xephi.authme.util.Utils;
-
/**
*/
public class AuthMePlayerListener16 implements Listener {
@@ -17,6 +16,7 @@ public class AuthMePlayerListener16 implements Listener {
/**
* Constructor for AuthMePlayerListener16.
+ *
* @param plugin AuthMe
*/
public AuthMePlayerListener16(AuthMe plugin) {
@@ -25,6 +25,7 @@ public class AuthMePlayerListener16 implements Listener {
/**
* Method onPlayerEditBook.
+ *
* @param event PlayerEditBookEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
diff --git a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener18.java b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener18.java
index 48815929f..ac1dc42b7 100644
--- a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener18.java
+++ b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener18.java
@@ -1,14 +1,13 @@
package fr.xephi.authme.listener;
+import fr.xephi.authme.AuthMe;
+import fr.xephi.authme.util.Utils;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
-import fr.xephi.authme.AuthMe;
-import fr.xephi.authme.util.Utils;
-
/**
*/
public class AuthMePlayerListener18 implements Listener {
@@ -17,6 +16,7 @@ public class AuthMePlayerListener18 implements Listener {
/**
* Constructor for AuthMePlayerListener18.
+ *
* @param plugin AuthMe
*/
public AuthMePlayerListener18(AuthMe plugin) {
@@ -25,6 +25,7 @@ public class AuthMePlayerListener18 implements Listener {
/**
* Method onPlayerInteractAtEntity.
+ *
* @param event PlayerInteractAtEntityEvent
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
diff --git a/src/main/java/fr/xephi/authme/listener/AuthMeServerListener.java b/src/main/java/fr/xephi/authme/listener/AuthMeServerListener.java
index ec17eaaf5..51670d37b 100644
--- a/src/main/java/fr/xephi/authme/listener/AuthMeServerListener.java
+++ b/src/main/java/fr/xephi/authme/listener/AuthMeServerListener.java
@@ -1,17 +1,16 @@
package fr.xephi.authme.listener;
+import fr.xephi.authme.AuthMe;
+import fr.xephi.authme.ConsoleLogger;
+import fr.xephi.authme.settings.Messages;
+import fr.xephi.authme.settings.Settings;
+import fr.xephi.authme.util.GeoLiteAPI;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.event.server.ServerListPingEvent;
-
-import fr.xephi.authme.AuthMe;
-import fr.xephi.authme.ConsoleLogger;
-import fr.xephi.authme.settings.Messages;
-import fr.xephi.authme.settings.Settings;
-import fr.xephi.authme.util.Utils;
import org.bukkit.plugin.Plugin;
/**
@@ -23,6 +22,7 @@ public class AuthMeServerListener implements Listener {
/**
* Constructor for AuthMeServerListener.
+ *
* @param plugin AuthMe
*/
public AuthMeServerListener(AuthMe plugin) {
@@ -31,6 +31,7 @@ public class AuthMeServerListener implements Listener {
/**
* Method onServerPing.
+ *
* @param event ServerListPingEvent
*/
@EventHandler(priority = EventPriority.HIGHEST)
@@ -40,10 +41,10 @@ public class AuthMeServerListener implements Listener {
if (Settings.countries.isEmpty())
return;
if (!Settings.countriesBlacklist.isEmpty()) {
- if (Settings.countriesBlacklist.contains(Utils.getCountryCode(event.getAddress().getHostAddress())))
+ if (Settings.countriesBlacklist.contains(GeoLiteAPI.getCountryCode(event.getAddress().getHostAddress())))
event.setMotd(m.send("country_banned")[0]);
}
- if (Settings.countries.contains(Utils.getCountryCode(event.getAddress().getHostAddress()))) {
+ if (Settings.countries.contains(GeoLiteAPI.getCountryCode(event.getAddress().getHostAddress()))) {
event.setMotd(plugin.getServer().getMotd());
} else {
event.setMotd(m.send("country_banned")[0]);
@@ -52,6 +53,7 @@ public class AuthMeServerListener implements Listener {
/**
* Method onPluginDisable.
+ *
* @param event PluginDisableEvent
*/
@EventHandler(priority = EventPriority.HIGHEST)
@@ -60,11 +62,11 @@ public class AuthMeServerListener implements Listener {
Plugin pluginInstance = event.getPlugin();
// Make sure the plugin instance isn't null
- if(pluginInstance == null)
+ if (pluginInstance == null)
return;
// Make sure it's not this plugin itself
- if(pluginInstance.equals(this.plugin))
+ if (pluginInstance.equals(this.plugin))
return;
// Call the onPluginDisable method in the permissions manager
@@ -98,6 +100,7 @@ public class AuthMeServerListener implements Listener {
/**
* Method onPluginEnable.
+ *
* @param event PluginEnableEvent
*/
@EventHandler(priority = EventPriority.HIGHEST)
diff --git a/src/main/java/fr/xephi/authme/modules/Module.java b/src/main/java/fr/xephi/authme/modules/Module.java
index f6263ad23..f64349cfe 100644
--- a/src/main/java/fr/xephi/authme/modules/Module.java
+++ b/src/main/java/fr/xephi/authme/modules/Module.java
@@ -4,6 +4,26 @@ package fr.xephi.authme.modules;
*/
public abstract class Module {
+ /**
+ * Method getName.
+ *
+ * @return String
+ */
+ public abstract String getName();
+
+ /**
+ * Method getType.
+ *
+ * @return ModuleType
+ */
+ public abstract ModuleType getType();
+
+ public void load() {
+ }
+
+ public void unload() {
+ }
+
/**
*/
enum ModuleType {
@@ -15,22 +35,4 @@ public abstract class Module {
EMAILS,
CUSTOM
}
-
- /**
- * Method getName.
-
- * @return String */
- public abstract String getName();
-
- /**
- * Method getType.
-
- * @return ModuleType */
- public abstract ModuleType getType();
-
- public void load() {
- }
-
- public void unload() {
- }
}
diff --git a/src/main/java/fr/xephi/authme/modules/ModuleManager.java b/src/main/java/fr/xephi/authme/modules/ModuleManager.java
index e83710f84..015c7e6c7 100644
--- a/src/main/java/fr/xephi/authme/modules/ModuleManager.java
+++ b/src/main/java/fr/xephi/authme/modules/ModuleManager.java
@@ -1,5 +1,9 @@
package fr.xephi.authme.modules;
+import fr.xephi.authme.AuthMe;
+import fr.xephi.authme.ConsoleLogger;
+import fr.xephi.authme.settings.Settings;
+
import java.io.File;
import java.io.IOException;
import java.net.URL;
@@ -11,10 +15,6 @@ import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
-import fr.xephi.authme.AuthMe;
-import fr.xephi.authme.ConsoleLogger;
-import fr.xephi.authme.settings.Settings;
-
/**
*/
public class ModuleManager {
@@ -23,6 +23,7 @@ public class ModuleManager {
/**
* Constructor for ModuleManager.
+ *
* @param plugin AuthMe
*/
public ModuleManager(AuthMe plugin) {
@@ -30,9 +31,10 @@ public class ModuleManager {
/**
* Method isModuleEnabled.
+ *
* @param name String
-
- * @return boolean */
+ * @return boolean
+ */
public boolean isModuleEnabled(String name) {
for (Module m : modules) {
if (m.getName().equalsIgnoreCase(name))
@@ -43,9 +45,10 @@ public class ModuleManager {
/**
* Method isModuleEnabled.
+ *
* @param type Module.ModuleType
-
- * @return boolean */
+ * @return boolean
+ */
public boolean isModuleEnabled(Module.ModuleType type) {
for (Module m : modules) {
if (m.getType() == type)
@@ -56,9 +59,10 @@ public class ModuleManager {
/**
* Method getModule.
+ *
* @param name String
-
- * @return Module */
+ * @return Module
+ */
public Module getModule(String name) {
for (Module m : modules) {
if (m.getName().equalsIgnoreCase(name))
@@ -69,9 +73,10 @@ public class ModuleManager {
/**
* Method getModule.
+ *
* @param type Module.ModuleType
-
- * @return Module */
+ * @return Module
+ */
public Module getModule(Module.ModuleType type) {
for (Module m : modules) {
if (m.getType() == type)
@@ -82,8 +87,9 @@ public class ModuleManager {
/**
* Method loadModules.
-
- * @return int */
+ *
+ * @return int
+ */
public int loadModules() {
File dir = Settings.MODULE_FOLDER;
int count = 0;
@@ -142,13 +148,14 @@ public class ModuleManager {
return count;
}
- public void reloadModules(){
+ public void reloadModules() {
unloadModules();
loadModules();
}
/**
* Method unloadModule.
+ *
* @param name String
*/
public void unloadModule(String name) {
diff --git a/src/main/java/fr/xephi/authme/permission/PermissionsManager.java b/src/main/java/fr/xephi/authme/permission/PermissionsManager.java
index a2af1ba4a..086d158ff 100644
--- a/src/main/java/fr/xephi/authme/permission/PermissionsManager.java
+++ b/src/main/java/fr/xephi/authme/permission/PermissionsManager.java
@@ -29,10 +29,10 @@ import java.util.logging.Logger;
/**
* PermissionsManager.
- *
+ *
* A permissions manager, to manage and use various permissions systems.
* This manager supports dynamic plugin hooking and various other features.
- *
+ *
* Written by Tim Visée.
*
* @author Tim Visée, http://timvisee.com
@@ -40,6 +40,10 @@ import java.util.logging.Logger;
*/
public class PermissionsManager {
+ /**
+ * Vault instance.
+ */
+ public Permission vaultPerms = null;
/**
* Server instance.
*/
@@ -52,38 +56,29 @@ public class PermissionsManager {
* Logger instance.
*/
private Logger log;
-
/**
* Type of permissions system that is currently used.
*/
private PermissionsSystemType permsType = PermissionsSystemType.NONE;
-
/**
* Essentials group manager instance.
*/
private GroupManager groupManagerPerms;
-
/**
* Permissions manager instance for the legacy permissions system.
*/
private PermissionHandler defaultPerms;
-
/**
* zPermissions service instance.
*/
private ZPermissionsService zPermissionsService;
- /**
- * Vault instance.
- */
- public Permission vaultPerms = null;
-
/**
* Constructor.
*
* @param server Server instance
* @param plugin Plugin instance
- * @param log Logger
+ * @param log Logger
*/
public PermissionsManager(Server server, Plugin plugin, Logger log) {
this.server = server;
@@ -124,16 +119,16 @@ public class PermissionsManager {
// PermissionsEx, check if it's available
try {
Plugin pex = pm.getPlugin("PermissionsEx");
- if(pex != null) {
+ if (pex != null) {
PermissionManager pexPerms = PermissionsEx.getPermissionManager();
- if(pexPerms != null) {
+ if (pexPerms != null) {
permsType = PermissionsSystemType.PERMISSIONS_EX;
System.out.println("[" + plugin.getName() + "] Hooked into PermissionsEx!");
return permsType;
}
}
- } catch(Exception ex) {
+ } catch (Exception ex) {
// An error occurred, show a warning message
System.out.println("[" + plugin.getName() + "] Error while hooking into PermissionsEx!");
}
@@ -141,12 +136,12 @@ public class PermissionsManager {
// PermissionsBukkit, check if it's available
try {
Plugin bukkitPerms = pm.getPlugin("PermissionsBukkit");
- if(bukkitPerms != null) {
+ if (bukkitPerms != null) {
permsType = PermissionsSystemType.PERMISSIONS_BUKKIT;
System.out.println("[" + plugin.getName() + "] Hooked into PermissionsBukkit!");
return permsType;
}
- } catch(Exception ex) {
+ } catch (Exception ex) {
// An error occurred, show a warning message
System.out.println("[" + plugin.getName() + "] Error while hooking into PermissionsBukkit!");
}
@@ -154,12 +149,12 @@ public class PermissionsManager {
// bPermissions, check if it's available
try {
Plugin bPerms = pm.getPlugin("bPermissions");
- if(bPerms != null) {
+ if (bPerms != null) {
permsType = PermissionsSystemType.B_PERMISSIONS;
System.out.println("[" + plugin.getName() + "] Hooked into bPermissions!");
return permsType;
}
- } catch(Exception ex) {
+ } catch (Exception ex) {
// An error occurred, show a warning message
System.out.println("[" + plugin.getName() + "] Error while hooking into bPermissions!");
}
@@ -167,13 +162,13 @@ public class PermissionsManager {
// Essentials Group Manager, check if it's available
try {
final Plugin groupManagerPlugin = pm.getPlugin("GroupManager");
- if(groupManagerPlugin != null && groupManagerPlugin.isEnabled()) {
+ if (groupManagerPlugin != null && groupManagerPlugin.isEnabled()) {
permsType = PermissionsSystemType.ESSENTIALS_GROUP_MANAGER;
groupManagerPerms = (GroupManager) groupManagerPlugin;
System.out.println("[" + plugin.getName() + "] Hooked into Essentials Group Manager!");
return permsType;
}
- } catch(Exception ex) {
+ } catch (Exception ex) {
// An error occurred, show a warning message
System.out.println("[" + plugin.getName() + "] Error while hooking into Essentials Group Manager!");
}
@@ -181,15 +176,15 @@ public class PermissionsManager {
// zPermissions, check if it's available
try {
Plugin zPerms = pm.getPlugin("zPermissions");
- if(zPerms != null) {
+ if (zPerms != null) {
zPermissionsService = Bukkit.getServicesManager().load(ZPermissionsService.class);
- if(zPermissionsService != null) {
+ if (zPermissionsService != null) {
permsType = PermissionsSystemType.Z_PERMISSIONS;
System.out.println("[" + plugin.getName() + "] Hooked into zPermissions!");
return permsType;
}
}
- } catch(Exception ex) {
+ } catch (Exception ex) {
// An error occurred, show a warning message
System.out.println("[" + plugin.getName() + "] Error while hooking into zPermissions!");
}
@@ -197,11 +192,11 @@ public class PermissionsManager {
// Vault, check if it's available
try {
final Plugin vaultPlugin = pm.getPlugin("Vault");
- if(vaultPlugin != null && vaultPlugin.isEnabled()) {
+ if (vaultPlugin != null && vaultPlugin.isEnabled()) {
RegisteredServiceProvider permissionProvider = this.server.getServicesManager().getRegistration(Permission.class);
- if(permissionProvider != null) {
+ if (permissionProvider != null) {
vaultPerms = permissionProvider.getProvider();
- if(vaultPerms.isEnabled()) {
+ if (vaultPerms.isEnabled()) {
permsType = PermissionsSystemType.VAULT;
System.out.println("[" + plugin.getName() + "] Hooked into Vault Permissions!");
return permsType;
@@ -210,7 +205,7 @@ public class PermissionsManager {
}
}
}
- } catch(Exception ex) {
+ } catch (Exception ex) {
// An error occurred, show a warning message
System.out.println("[" + plugin.getName() + "] Error while hooking into Vault Permissions!");
}
@@ -218,13 +213,13 @@ public class PermissionsManager {
// Permissions, check if it's available
try {
Plugin testPerms = pm.getPlugin("Permissions");
- if(testPerms != null) {
+ if (testPerms != null) {
permsType = PermissionsSystemType.PERMISSIONS;
this.defaultPerms = ((Permissions) testPerms).getHandler();
System.out.println("[" + plugin.getName() + "] Hooked into Permissions!");
return PermissionsSystemType.PERMISSIONS;
}
- } catch(Exception ex) {
+ } catch (Exception ex) {
// An error occurred, show a warning message
System.out.println("[" + plugin.getName() + "] Error while hooking into Permissions!");
}
@@ -271,7 +266,7 @@ public class PermissionsManager {
String pluginName = plugin.getName();
// Check if any known permissions system is enabling
- if(pluginName.equals("PermissionsEx") || pluginName.equals("PermissionsBukkit") ||
+ if (pluginName.equals("PermissionsEx") || pluginName.equals("PermissionsBukkit") ||
pluginName.equals("bPermissions") || pluginName.equals("GroupManager") ||
pluginName.equals("zPermissions") || pluginName.equals("Vault") ||
pluginName.equals("Permissions")) {
@@ -291,7 +286,7 @@ public class PermissionsManager {
String pluginName = plugin.getName();
// Is the WorldGuard plugin disabled
- if(pluginName.equals("PermissionsEx") || pluginName.equals("PermissionsBukkit") ||
+ if (pluginName.equals("PermissionsEx") || pluginName.equals("PermissionsBukkit") ||
pluginName.equals("bPermissions") || pluginName.equals("GroupManager") ||
pluginName.equals("zPermissions") || pluginName.equals("Vault") ||
pluginName.equals("Permissions")) {
@@ -321,9 +316,8 @@ public class PermissionsManager {
/**
* Check if the player has permission. If no permissions system is used, the player has to be OP.
*
- * @param player The player.
+ * @param player The player.
* @param permsNode Permissions node.
- *
* @return True if the player has permission.
*/
public boolean hasPermission(Player player, String permsNode) {
@@ -333,18 +327,17 @@ public class PermissionsManager {
/**
* Check if a player has permission.
*
- * @param player The player.
+ * @param player The player.
* @param permsNode The permission node.
- * @param def Default returned if no permissions system is used.
- *
+ * @param def Default returned if no permissions system is used.
* @return True if the player has permission.
*/
public boolean hasPermission(Player player, String permsNode, boolean def) {
// If no permissions system is used, return the default value
- if(!isEnabled())
+ if (!isEnabled())
return def;
- switch(this.permsType) {
+ switch (this.permsType) {
case PERMISSIONS_EX:
// Permissions Ex
PermissionUser user = PermissionsEx.getUser(player);
@@ -367,7 +360,7 @@ public class PermissionsManager {
// zPermissions
@SuppressWarnings("deprecation")
Map perms = zPermissionsService.getPlayerPermissions(player.getWorld().getName(), null, player.getName());
- if(perms.containsKey(permsNode))
+ if (perms.containsKey(permsNode))
return perms.get(permsNode);
else
return def;
@@ -398,10 +391,10 @@ public class PermissionsManager {
*/
public boolean hasGroupSupport() {
// If no permissions system is used, return false
- if(!isEnabled())
+ if (!isEnabled())
return false;
- switch(this.permsType) {
+ switch (this.permsType) {
case PERMISSIONS_EX:
case PERMISSIONS_BUKKIT:
case B_PERMISSIONS:
@@ -432,16 +425,15 @@ public class PermissionsManager {
* Get the permission groups of a player, if available.
*
* @param player The player.
- *
* @return Permission groups, or an empty list if this feature is not supported.
*/
@SuppressWarnings({"unchecked", "rawtypes", "deprecation"})
public List getGroups(Player player) {
// If no permissions system is used, return an empty list
- if(!isEnabled())
+ if (!isEnabled())
return new ArrayList<>();
- switch(this.permsType) {
+ switch (this.permsType) {
case PERMISSIONS_EX:
// Permissions Ex
PermissionUser user = PermissionsEx.getUser(player);
@@ -459,7 +451,7 @@ public class PermissionsManager {
case ESSENTIALS_GROUP_MANAGER:
// Essentials Group Manager
final AnjoPermissionsHandler handler = groupManagerPerms.getWorldsHolder().getWorldPermissions(player);
- if(handler == null)
+ if (handler == null)
return new ArrayList<>();
return Arrays.asList(handler.getGroups(player.getName()));
@@ -477,7 +469,7 @@ public class PermissionsManager {
List groups = new ArrayList<>();
// Get the groups and add each to the list
- for(Group group : this.defaultPerms.getGroups(player.getName()))
+ for (Group group : this.defaultPerms.getGroups(player.getName()))
groups.add(group.getName());
// Return the groups
@@ -497,16 +489,15 @@ public class PermissionsManager {
* Get the primary group of a player, if available.
*
* @param player The player.
- *
* @return The name of the primary permission group. Or null.
*/
@SuppressWarnings("deprecation")
public String getPrimaryGroup(Player player) {
// If no permissions system is used, return an empty list
- if(!isEnabled())
+ if (!isEnabled())
return null;
- switch(this.permsType) {
+ switch (this.permsType) {
case PERMISSIONS_EX:
case PERMISSIONS_BUKKIT:
case B_PERMISSIONS:
@@ -515,7 +506,7 @@ public class PermissionsManager {
List groups = getGroups(player);
// Make sure there is any group available, or return null
- if(groups.size() == 0)
+ if (groups.size() == 0)
return null;
// Return the first group
@@ -524,7 +515,7 @@ public class PermissionsManager {
case ESSENTIALS_GROUP_MANAGER:
// Essentials Group Manager
final AnjoPermissionsHandler handler = groupManagerPerms.getWorldsHolder().getWorldPermissions(player);
- if(handler == null)
+ if (handler == null)
return null;
return handler.getGroup(player.getName());
@@ -549,18 +540,17 @@ public class PermissionsManager {
/**
* Check whether the player is in the specified group.
*
- * @param player The player.
+ * @param player The player.
* @param groupName The group name.
- *
* @return True if the player is in the specified group, false otherwise.
* False is also returned if groups aren't supported by the used permissions system.
*/
public boolean inGroup(Player player, String groupName) {
// If no permissions system is used, return false
- if(!isEnabled())
+ if (!isEnabled())
return false;
- switch(this.permsType) {
+ switch (this.permsType) {
case PERMISSIONS_EX:
// Permissions Ex
PermissionUser user = PermissionsEx.getUser(player);
@@ -572,8 +562,8 @@ public class PermissionsManager {
List groupNames = getGroups(player);
// Check whether the list contains the group name, return the result
- for(String entry : groupNames)
- if(entry.equals(groupName))
+ for (String entry : groupNames)
+ if (entry.equals(groupName))
return true;
return false;
@@ -607,19 +597,18 @@ public class PermissionsManager {
/**
* Add the permission group of a player, if supported.
*
- * @param player The player
+ * @param player The player
* @param groupName The name of the group.
- *
* @return True if succeed, false otherwise.
* False is also returned if this feature isn't supported for the current permissions system.
*/
public boolean addGroup(Player player, String groupName) {
// If no permissions system is used, return false
- if(!isEnabled())
+ if (!isEnabled())
return false;
// Set the group the proper way
- switch(this.permsType) {
+ switch (this.permsType) {
case PERMISSIONS_EX:
// Permissions Ex
PermissionUser user = PermissionsEx.getUser(player);
@@ -669,21 +658,20 @@ public class PermissionsManager {
/**
* Add the permission groups of a player, if supported.
*
- * @param player The player
+ * @param player The player
* @param groupNames The name of the groups to add.
- *
* @return True if succeed, false otherwise.
* False is also returned if this feature isn't supported for the current permissions system.
*/
public boolean addGroups(Player player, List groupNames) {
// If no permissions system is used, return false
- if(!isEnabled())
+ if (!isEnabled())
return false;
// Add each group to the user
boolean result = true;
- for(String groupName : groupNames)
- if(!addGroup(player, groupName))
+ for (String groupName : groupNames)
+ if (!addGroup(player, groupName))
result = false;
// Return the result
@@ -693,19 +681,18 @@ public class PermissionsManager {
/**
* Remove the permission group of a player, if supported.
*
- * @param player The player
+ * @param player The player
* @param groupName The name of the group.
- *
* @return True if succeed, false otherwise.
* False is also returned if this feature isn't supported for the current permissions system.
*/
public boolean removeGroup(Player player, String groupName) {
// If no permissions system is used, return false
- if(!isEnabled())
+ if (!isEnabled())
return false;
// Set the group the proper way
- switch(this.permsType) {
+ switch (this.permsType) {
case PERMISSIONS_EX:
// Permissions Ex
PermissionUser user = PermissionsEx.getUser(player);
@@ -755,21 +742,20 @@ public class PermissionsManager {
/**
* Remove the permission groups of a player, if supported.
*
- * @param player The player
+ * @param player The player
* @param groupNames The name of the groups to add.
- *
* @return True if succeed, false otherwise.
* False is also returned if this feature isn't supported for the current permissions system.
*/
public boolean removeGroups(Player player, List groupNames) {
// If no permissions system is used, return false
- if(!isEnabled())
+ if (!isEnabled())
return false;
// Add each group to the user
boolean result = true;
- for(String groupName : groupNames)
- if(!removeGroup(player, groupName))
+ for (String groupName : groupNames)
+ if (!removeGroup(player, groupName))
result = false;
// Return the result
@@ -780,15 +766,14 @@ public class PermissionsManager {
* Set the permission group of a player, if supported.
* This clears the current groups of the player.
*
- * @param player The player
+ * @param player The player
* @param groupName The name of the group.
- *
* @return True if succeed, false otherwise.
* False is also returned if this feature isn't supported for the current permissions system.
*/
public boolean setGroup(Player player, String groupName) {
// If no permissions system is used, return false
- if(!isEnabled())
+ if (!isEnabled())
return false;
// Create a list of group names
@@ -796,7 +781,7 @@ public class PermissionsManager {
groupNames.add(groupName);
// Set the group the proper way
- switch(this.permsType) {
+ switch (this.permsType) {
case PERMISSIONS_EX:
// Permissions Ex
PermissionUser user = PermissionsEx.getUser(player);
@@ -850,29 +835,28 @@ public class PermissionsManager {
* Set the permission groups of a player, if supported.
* This clears the current groups of the player.
*
- * @param player The player
+ * @param player The player
* @param groupNames The name of the groups to set.
- *
* @return True if succeed, false otherwise.
* False is also returned if this feature isn't supported for the current permissions system.
*/
public boolean setGroups(Player player, List groupNames) {
// If no permissions system is used or if there's no group supplied, return false
- if(!isEnabled() || groupNames.size() <= 0)
+ if (!isEnabled() || groupNames.size() <= 0)
return false;
// Set the main group
- if(!setGroup(player, groupNames.get(0)))
+ if (!setGroup(player, groupNames.get(0)))
return false;
// Add the rest of the groups
boolean result = true;
- for(int i = 1; i < groupNames.size(); i++) {
+ for (int i = 1; i < groupNames.size(); i++) {
// Get the group name
String groupName = groupNames.get(0);
// Add this group
- if(!addGroup(player, groupName))
+ if (!addGroup(player, groupName))
result = false;
}
@@ -886,13 +870,12 @@ public class PermissionsManager {
* in it's primary group. All the subgroups are removed just fine.
*
* @param player The player to remove all groups from.
- *
* @return True if succeed, false otherwise.
* False will also be returned if this feature isn't supported for the used permissions system.
*/
public boolean removeAllGroups(Player player) {
// If no permissions system is used, return false
- if(!isEnabled())
+ if (!isEnabled())
return false;
// Get a list of current groups
diff --git a/src/main/java/fr/xephi/authme/process/Management.java b/src/main/java/fr/xephi/authme/process/Management.java
index 1030eeddc..75c0899c8 100644
--- a/src/main/java/fr/xephi/authme/process/Management.java
+++ b/src/main/java/fr/xephi/authme/process/Management.java
@@ -1,8 +1,5 @@
package fr.xephi.authme.process;
-import org.bukkit.entity.Player;
-import org.bukkit.scheduler.BukkitScheduler;
-
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.process.email.AsyncChangeEmail;
import fr.xephi.authme.process.join.AsyncronousJoin;
@@ -13,20 +10,22 @@ import fr.xephi.authme.process.register.AsyncRegister;
import fr.xephi.authme.process.unregister.AsyncronousUnregister;
import fr.xephi.authme.security.RandomString;
import fr.xephi.authme.settings.Settings;
+import org.bukkit.entity.Player;
+import org.bukkit.scheduler.BukkitScheduler;
/**
-
* @author Gabriele
* @version $Revision: 1.0 $
*/
public class Management {
+ public static RandomString rdm = new RandomString(Settings.captchaLength);
private final AuthMe plugin;
private final BukkitScheduler sched;
- public static RandomString rdm = new RandomString(Settings.captchaLength);
/**
* Constructor for Management.
+ *
* @param plugin AuthMe
*/
public Management(AuthMe plugin) {
@@ -36,8 +35,9 @@ public class Management {
/**
* Method performLogin.
- * @param player Player
- * @param password String
+ *
+ * @param player Player
+ * @param password String
* @param forceLogin boolean
*/
public void performLogin(final Player player, final String password, final boolean forceLogin) {
@@ -52,6 +52,7 @@ public class Management {
/**
* Method performLogout.
+ *
* @param player Player
*/
public void performLogout(final Player player) {
@@ -66,9 +67,10 @@ public class Management {
/**
* Method performRegister.
- * @param player Player
+ *
+ * @param player Player
* @param password String
- * @param email String
+ * @param email String
*/
public void performRegister(final Player player, final String password, final String email) {
sched.runTaskAsynchronously(plugin, new Runnable() {
@@ -82,9 +84,10 @@ public class Management {
/**
* Method performUnregister.
- * @param player Player
+ *
+ * @param player Player
* @param password String
- * @param force boolean
+ * @param force boolean
*/
public void performUnregister(final Player player, final String password, final boolean force) {
sched.runTaskAsynchronously(plugin, new Runnable() {
@@ -98,6 +101,7 @@ public class Management {
/**
* Method performJoin.
+ *
* @param player Player
*/
public void performJoin(final Player player) {
@@ -113,6 +117,7 @@ public class Management {
/**
* Method performQuit.
+ *
* @param player Player
* @param isKick boolean
*/
@@ -129,8 +134,9 @@ public class Management {
/**
* Method performAddEmail.
- * @param player Player
- * @param newEmail String
+ *
+ * @param player Player
+ * @param newEmail String
* @param newEmailVerify String
*/
public void performAddEmail(final Player player, final String newEmail, final String newEmailVerify) {
@@ -144,7 +150,8 @@ public class Management {
/**
* Method performChangeEmail.
- * @param player Player
+ *
+ * @param player Player
* @param oldEmail String
* @param newEmail String
*/
diff --git a/src/main/java/fr/xephi/authme/process/email/AsyncChangeEmail.java b/src/main/java/fr/xephi/authme/process/email/AsyncChangeEmail.java
index 3fddc1625..e85bac0af 100644
--- a/src/main/java/fr/xephi/authme/process/email/AsyncChangeEmail.java
+++ b/src/main/java/fr/xephi/authme/process/email/AsyncChangeEmail.java
@@ -1,15 +1,14 @@
package fr.xephi.authme.process.email;
-import java.util.Arrays;
-
-import org.bukkit.entity.Player;
-
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings;
+import org.bukkit.entity.Player;
+
+import java.util.Arrays;
/**
*/
@@ -24,10 +23,11 @@ public class AsyncChangeEmail {
/**
* Constructor for AsyncChangeEmail.
- * @param player Player
- * @param plugin AuthMe
- * @param oldEmail String
- * @param newEmail String
+ *
+ * @param player Player
+ * @param plugin AuthMe
+ * @param oldEmail String
+ * @param newEmail String
* @param newEmailVerify String
*/
public AsyncChangeEmail(Player player, AuthMe plugin, String oldEmail, String newEmail, String newEmailVerify) {
@@ -41,8 +41,9 @@ public class AsyncChangeEmail {
/**
* Constructor for AsyncChangeEmail.
- * @param player Player
- * @param plugin AuthMe
+ *
+ * @param player Player
+ * @param plugin AuthMe
* @param oldEmail String
* @param newEmail String
*/
diff --git a/src/main/java/fr/xephi/authme/process/join/AsyncronousJoin.java b/src/main/java/fr/xephi/authme/process/join/AsyncronousJoin.java
index 87faa3d22..5bddc07d7 100644
--- a/src/main/java/fr/xephi/authme/process/join/AsyncronousJoin.java
+++ b/src/main/java/fr/xephi/authme/process/join/AsyncronousJoin.java
@@ -1,15 +1,5 @@
package fr.xephi.authme.process.join;
-import org.bukkit.Bukkit;
-import org.bukkit.GameMode;
-import org.bukkit.Location;
-import org.bukkit.Material;
-import org.bukkit.entity.Player;
-import org.bukkit.potion.PotionEffect;
-import org.bukkit.potion.PotionEffectType;
-import org.bukkit.scheduler.BukkitScheduler;
-import org.bukkit.scheduler.BukkitTask;
-
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth;
@@ -27,6 +17,15 @@ import fr.xephi.authme.task.MessageTask;
import fr.xephi.authme.task.TimeoutTask;
import fr.xephi.authme.util.Utils;
import fr.xephi.authme.util.Utils.GroupType;
+import org.bukkit.Bukkit;
+import org.bukkit.GameMode;
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.entity.Player;
+import org.bukkit.potion.PotionEffect;
+import org.bukkit.potion.PotionEffectType;
+import org.bukkit.scheduler.BukkitScheduler;
+import org.bukkit.scheduler.BukkitTask;
/**
*/
@@ -41,8 +40,9 @@ public class AsyncronousJoin {
/**
* Constructor for AsyncronousJoin.
- * @param player Player
- * @param plugin AuthMe
+ *
+ * @param player Player
+ * @param plugin AuthMe
* @param database DataSource
*/
public AsyncronousJoin(Player player, AuthMe plugin, DataSource database) {
@@ -68,7 +68,7 @@ public class AsyncronousJoin {
}
if (!plugin.canConnect()) {
- final GameMode gM = AuthMePlayerListener.gameMode.get(name);
+ final GameMode gM = AuthMePlayerListener.gameMode.get(name);
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
@@ -248,15 +248,16 @@ public class AsyncronousJoin {
}
String[] msg = isAuthAvailable ? m.send("login_msg") :
- m.send("reg_" + (Settings.emailRegistration? "email_" : "") + "msg");
+ m.send("reg_" + (Settings.emailRegistration ? "email_" : "") + "msg");
BukkitTask msgTask = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, msg, msgInterval));
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgTask);
}
/**
* Method needFirstSpawn.
-
- * @return boolean */
+ *
+ * @return boolean
+ */
private boolean needFirstSpawn() {
if (player.hasPlayedBefore())
return false;
@@ -283,7 +284,8 @@ public class AsyncronousJoin {
/**
* Method placePlayerSafely.
- * @param player Player
+ *
+ * @param player Player
* @param spawnLoc Location
*/
private void placePlayerSafely(final Player player, final Location spawnLoc) {
diff --git a/src/main/java/fr/xephi/authme/process/login/AsyncronousLogin.java b/src/main/java/fr/xephi/authme/process/login/AsyncronousLogin.java
index e6439d79b..2f75c7182 100644
--- a/src/main/java/fr/xephi/authme/process/login/AsyncronousLogin.java
+++ b/src/main/java/fr/xephi/authme/process/login/AsyncronousLogin.java
@@ -1,12 +1,5 @@
package fr.xephi.authme.process.login;
-import java.util.Date;
-import java.util.List;
-
-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.cache.auth.PlayerAuth;
@@ -21,11 +14,18 @@ import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.task.MessageTask;
import fr.xephi.authme.util.Utils;
+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 {
+ private static RandomString rdm = new RandomString(Settings.captchaLength);
protected Player player;
protected String name;
protected String realName;
@@ -33,16 +33,16 @@ public class AsyncronousLogin {
protected boolean forceLogin;
private AuthMe plugin;
private DataSource database;
- private static RandomString rdm = new RandomString(Settings.captchaLength);
private Messages m = Messages.getInstance();
/**
* Constructor for AsyncronousLogin.
- * @param player Player
- * @param password String
+ *
+ * @param player Player
+ * @param password String
* @param forceLogin boolean
- * @param plugin AuthMe
- * @param data DataSource
+ * @param plugin AuthMe
+ * @param data DataSource
*/
public AsyncronousLogin(Player player, String password, boolean forceLogin,
AuthMe plugin, DataSource data) {
@@ -57,16 +57,18 @@ public class AsyncronousLogin {
/**
* Method getIP.
-
- * @return String */
+ *
+ * @return String
+ */
protected String getIP() {
return plugin.getIP(player);
}
/**
* Method needsCaptcha.
-
- * @return boolean */
+ *
+ * @return boolean
+ */
protected boolean needsCaptcha() {
if (Settings.useCaptcha) {
if (!plugin.captcha.containsKey(name)) {
@@ -93,8 +95,9 @@ public class AsyncronousLogin {
/**
* Checks the precondition for authentication (like user known) and returns
* the playerAuth-State
-
- * @return PlayerAuth */
+ *
+ * @return PlayerAuth
+ */
protected PlayerAuth preAuth() {
if (PlayerCache.getInstance().isAuthenticated(name)) {
m.send(player, "logged_in");
@@ -221,8 +224,9 @@ public class AsyncronousLogin {
/**
* Method displayOtherAccounts.
+ *
* @param auth PlayerAuth
- * @param p Player
+ * @param p Player
*/
public void displayOtherAccounts(PlayerAuth auth, Player p) {
if (!Settings.displayOtherAccounts) {
diff --git a/src/main/java/fr/xephi/authme/process/login/ProcessSyncronousPlayerLogin.java b/src/main/java/fr/xephi/authme/process/login/ProcessSyncronousPlayerLogin.java
index 2b63d4ffc..8176ccb24 100644
--- a/src/main/java/fr/xephi/authme/process/login/ProcessSyncronousPlayerLogin.java
+++ b/src/main/java/fr/xephi/authme/process/login/ProcessSyncronousPlayerLogin.java
@@ -1,11 +1,5 @@
package fr.xephi.authme.process.login;
-import org.bukkit.Bukkit;
-import org.bukkit.Location;
-import org.bukkit.entity.Player;
-import org.bukkit.plugin.PluginManager;
-import org.bukkit.potion.PotionEffectType;
-
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.backup.JsonCache;
@@ -20,6 +14,11 @@ import fr.xephi.authme.listener.AuthMePlayerListener;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.util.Utils;
import fr.xephi.authme.util.Utils.GroupType;
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.entity.Player;
+import org.bukkit.plugin.PluginManager;
+import org.bukkit.potion.PotionEffectType;
/**
*/
@@ -36,12 +35,13 @@ public class ProcessSyncronousPlayerLogin implements Runnable {
/**
* Constructor for ProcessSyncronousPlayerLogin.
+ *
* @param player Player
* @param plugin AuthMe
- * @param data DataSource
+ * @param data DataSource
*/
public ProcessSyncronousPlayerLogin(Player player, AuthMe plugin,
- DataSource data) {
+ DataSource data) {
this.plugin = plugin;
this.database = data;
this.pm = plugin.getServer().getPluginManager();
@@ -54,8 +54,9 @@ public class ProcessSyncronousPlayerLogin implements Runnable {
/**
* Method getLimbo.
-
- * @return LimboPlayer */
+ *
+ * @return LimboPlayer
+ */
public LimboPlayer getLimbo() {
return limbo;
}
@@ -65,7 +66,7 @@ public class ProcessSyncronousPlayerLogin implements Runnable {
}
protected void restoreFlyghtState() {
- if(Settings.isForceSurvivalModeEnabled) {
+ if (Settings.isForceSurvivalModeEnabled) {
player.setAllowFlight(false);
player.setFlying(false);
return;
@@ -117,6 +118,7 @@ public class ProcessSyncronousPlayerLogin implements Runnable {
/**
* Method run.
+ *
* @see java.lang.Runnable#run()
*/
@Override
@@ -135,8 +137,7 @@ public class ProcessSyncronousPlayerLogin implements Runnable {
} else {
teleportBackFromSpawn();
}
- } else
- if (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName())) {
+ } else if (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName())) {
teleportToSpawn();
} else if (Settings.isSaveQuitLocationEnabled && auth.getQuitLocY() != 0) {
packQuitLocation();
@@ -150,10 +151,10 @@ public class ProcessSyncronousPlayerLogin implements Runnable {
} else {
player.setGameMode(limbo.getGameMode());
}
-
+
restoreFlyghtState();
- if (Settings.protectInventoryBeforeLogInEnabled && plugin.inventoryProtector != null) {
+ if (Settings.protectInventoryBeforeLogInEnabled && plugin.inventoryProtector != null) {
restoreInventory();
}
@@ -167,7 +168,7 @@ public class ProcessSyncronousPlayerLogin implements Runnable {
// We can now display the join message (if delayed)
String jm = AuthMePlayerListener.joinMessage.get(name);
if (jm != null) {
- if(!jm.isEmpty()) {
+ if (!jm.isEmpty()) {
for (Player p : Utils.getOnlinePlayers()) {
if (p.isOnline())
p.sendMessage(jm);
diff --git a/src/main/java/fr/xephi/authme/process/logout/AsyncronousLogout.java b/src/main/java/fr/xephi/authme/process/logout/AsyncronousLogout.java
index 6adb14522..8d614e935 100644
--- a/src/main/java/fr/xephi/authme/process/logout/AsyncronousLogout.java
+++ b/src/main/java/fr/xephi/authme/process/logout/AsyncronousLogout.java
@@ -1,8 +1,5 @@
package fr.xephi.authme.process.logout;
-import org.bukkit.entity.Player;
-import org.bukkit.scheduler.BukkitScheduler;
-
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache;
@@ -11,6 +8,8 @@ import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.util.Utils;
import fr.xephi.authme.util.Utils.GroupType;
+import org.bukkit.entity.Player;
+import org.bukkit.scheduler.BukkitScheduler;
/**
*/
@@ -25,12 +24,13 @@ public class AsyncronousLogout {
/**
* Constructor for AsyncronousLogout.
- * @param player Player
- * @param plugin AuthMe
+ *
+ * @param player Player
+ * @param plugin AuthMe
* @param database DataSource
*/
public AsyncronousLogout(Player player, AuthMe plugin,
- DataSource database) {
+ DataSource database) {
this.player = player;
this.plugin = plugin;
this.database = database;
diff --git a/src/main/java/fr/xephi/authme/process/logout/ProcessSyncronousPlayerLogout.java b/src/main/java/fr/xephi/authme/process/logout/ProcessSyncronousPlayerLogout.java
index 3281d3e1f..850a14d2b 100644
--- a/src/main/java/fr/xephi/authme/process/logout/ProcessSyncronousPlayerLogout.java
+++ b/src/main/java/fr/xephi/authme/process/logout/ProcessSyncronousPlayerLogout.java
@@ -1,12 +1,5 @@
package fr.xephi.authme.process.logout;
-import org.bukkit.Bukkit;
-import org.bukkit.entity.Player;
-import org.bukkit.potion.PotionEffect;
-import org.bukkit.potion.PotionEffectType;
-import org.bukkit.scheduler.BukkitScheduler;
-import org.bukkit.scheduler.BukkitTask;
-
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.limbo.LimboCache;
@@ -15,6 +8,12 @@ import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.task.MessageTask;
import fr.xephi.authme.task.TimeoutTask;
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+import org.bukkit.potion.PotionEffect;
+import org.bukkit.potion.PotionEffectType;
+import org.bukkit.scheduler.BukkitScheduler;
+import org.bukkit.scheduler.BukkitTask;
/**
*/
@@ -27,6 +26,7 @@ public class ProcessSyncronousPlayerLogout implements Runnable {
/**
* Constructor for ProcessSyncronousPlayerLogout.
+ *
* @param player Player
* @param plugin AuthMe
*/
@@ -38,6 +38,7 @@ public class ProcessSyncronousPlayerLogout implements Runnable {
/**
* Method run.
+ *
* @see java.lang.Runnable#run()
*/
@Override
diff --git a/src/main/java/fr/xephi/authme/process/quit/AsyncronousQuit.java b/src/main/java/fr/xephi/authme/process/quit/AsyncronousQuit.java
index 5d5e1ebe9..3cc273a56 100644
--- a/src/main/java/fr/xephi/authme/process/quit/AsyncronousQuit.java
+++ b/src/main/java/fr/xephi/authme/process/quit/AsyncronousQuit.java
@@ -1,10 +1,5 @@
package fr.xephi.authme.process.quit;
-import org.bukkit.Bukkit;
-import org.bukkit.Location;
-import org.bukkit.entity.Player;
-import org.bukkit.scheduler.BukkitTask;
-
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache;
@@ -14,6 +9,10 @@ import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.listener.AuthMePlayerListener;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.util.Utils;
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.entity.Player;
+import org.bukkit.scheduler.BukkitTask;
/**
*/
@@ -30,13 +29,14 @@ public class AsyncronousQuit {
/**
* Constructor for AsyncronousQuit.
- * @param p Player
- * @param plugin AuthMe
+ *
+ * @param p Player
+ * @param plugin AuthMe
* @param database DataSource
- * @param isKick boolean
+ * @param isKick boolean
*/
public AsyncronousQuit(Player p, AuthMe plugin, DataSource database,
- boolean isKick) {
+ boolean isKick) {
this.player = p;
this.plugin = plugin;
this.database = database;
diff --git a/src/main/java/fr/xephi/authme/process/quit/ProcessSyncronousPlayerQuit.java b/src/main/java/fr/xephi/authme/process/quit/ProcessSyncronousPlayerQuit.java
index 125d30213..6f1156591 100644
--- a/src/main/java/fr/xephi/authme/process/quit/ProcessSyncronousPlayerQuit.java
+++ b/src/main/java/fr/xephi/authme/process/quit/ProcessSyncronousPlayerQuit.java
@@ -1,10 +1,9 @@
package fr.xephi.authme.process.quit;
-import org.bukkit.GameMode;
-import org.bukkit.entity.Player;
-
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.settings.Settings;
+import org.bukkit.GameMode;
+import org.bukkit.entity.Player;
/**
*/
@@ -18,10 +17,11 @@ public class ProcessSyncronousPlayerQuit implements Runnable {
/**
* Constructor for ProcessSyncronousPlayerQuit.
- * @param plugin AuthMe
- * @param player Player
- * @param isOp boolean
- * @param isFlying boolean
+ *
+ * @param plugin AuthMe
+ * @param player Player
+ * @param isOp boolean
+ * @param isFlying boolean
* @param needToChange boolean
*/
public ProcessSyncronousPlayerQuit(AuthMe plugin, Player player
@@ -36,6 +36,7 @@ public class ProcessSyncronousPlayerQuit implements Runnable {
/**
* Method run.
+ *
* @see java.lang.Runnable#run()
*/
@Override
diff --git a/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java b/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java
index 15574f6c6..9cbe2c83e 100644
--- a/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java
+++ b/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java
@@ -1,10 +1,5 @@
package fr.xephi.authme.process.register;
-import java.security.NoSuchAlgorithmException;
-import java.util.Date;
-
-import org.bukkit.entity.Player;
-
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth;
@@ -13,6 +8,10 @@ import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings;
+import org.bukkit.entity.Player;
+
+import java.security.NoSuchAlgorithmException;
+import java.util.Date;
/**
*/
@@ -28,11 +27,12 @@ public class AsyncRegister {
/**
* Constructor for AsyncRegister.
- * @param player Player
+ *
+ * @param player Player
* @param password String
- * @param email String
- * @param plugin AuthMe
- * @param data DataSource
+ * @param email String
+ * @param plugin AuthMe
+ * @param data DataSource
*/
public AsyncRegister(Player player, String password, String email,
AuthMe plugin, DataSource data) {
@@ -46,17 +46,18 @@ public class AsyncRegister {
/**
* Method getIp.
-
- * @return String */
+ *
+ * @return String
+ */
protected String getIp() {
return plugin.getIP(player);
}
/**
* Method preRegisterCheck.
-
-
- * @return boolean * @throws Exception */
+ *
+ * @return boolean * @throws Exception
+ */
protected boolean preRegisterCheck() throws Exception {
String lowpass = password.toLowerCase();
if (PlayerCache.getInstance().isAuthenticated(name)) {
@@ -113,8 +114,9 @@ public class AsyncRegister {
/**
* Method emailRegister.
-
- * @throws Exception */
+ *
+ * @throws Exception
+ */
protected void emailRegister() throws Exception {
if (Settings.getmaxRegPerEmail > 0) {
if (!plugin.getPermissionsManager().hasPermission(player, "authme.allow2accounts") && database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) {
diff --git a/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java b/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java
index 0908d8a47..eb7f5f209 100644
--- a/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java
+++ b/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java
@@ -1,9 +1,5 @@
package fr.xephi.authme.process.register;
-import org.bukkit.entity.Player;
-import org.bukkit.scheduler.BukkitScheduler;
-import org.bukkit.scheduler.BukkitTask;
-
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.limbo.LimboCache;
@@ -13,6 +9,9 @@ import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.task.MessageTask;
import fr.xephi.authme.task.TimeoutTask;
import fr.xephi.authme.util.Utils;
+import org.bukkit.entity.Player;
+import org.bukkit.scheduler.BukkitScheduler;
+import org.bukkit.scheduler.BukkitTask;
/**
*/
@@ -25,6 +24,7 @@ public class ProcessSyncEmailRegister implements Runnable {
/**
* Constructor for ProcessSyncEmailRegister.
+ *
* @param player Player
* @param plugin AuthMe
*/
@@ -36,6 +36,7 @@ public class ProcessSyncEmailRegister implements Runnable {
/**
* Method run.
+ *
* @see java.lang.Runnable#run()
*/
@Override
@@ -54,7 +55,7 @@ public class ProcessSyncEmailRegister implements Runnable {
BukkitTask id = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name, player), time);
limbo.setTimeoutTaskId(id);
}
- if (limbo != null){
+ if (limbo != null) {
limbo.getMessageTaskId().cancel();
BukkitTask nwMsg = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, m.send("login_msg"), msgInterval));
limbo.setMessageTaskId(nwMsg);
diff --git a/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousPasswordRegister.java b/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousPasswordRegister.java
index ca1a67e0a..60b2865de 100644
--- a/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousPasswordRegister.java
+++ b/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousPasswordRegister.java
@@ -1,12 +1,5 @@
package fr.xephi.authme.process.register;
-import org.bukkit.Bukkit;
-import org.bukkit.GameMode;
-import org.bukkit.entity.Player;
-import org.bukkit.potion.PotionEffectType;
-import org.bukkit.scheduler.BukkitScheduler;
-import org.bukkit.scheduler.BukkitTask;
-
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.limbo.LimboCache;
@@ -18,6 +11,12 @@ import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.task.MessageTask;
import fr.xephi.authme.task.TimeoutTask;
import fr.xephi.authme.util.Utils;
+import org.bukkit.Bukkit;
+import org.bukkit.GameMode;
+import org.bukkit.entity.Player;
+import org.bukkit.potion.PotionEffectType;
+import org.bukkit.scheduler.BukkitScheduler;
+import org.bukkit.scheduler.BukkitTask;
/**
*/
@@ -30,6 +29,7 @@ public class ProcessSyncronousPasswordRegister implements Runnable {
/**
* Constructor for ProcessSyncronousPasswordRegister.
+ *
* @param player Player
* @param plugin AuthMe
*/
@@ -53,6 +53,7 @@ public class ProcessSyncronousPasswordRegister implements Runnable {
/**
* Method forceLogin.
+ *
* @param player Player
*/
protected void forceLogin(Player player) {
@@ -76,6 +77,7 @@ public class ProcessSyncronousPasswordRegister implements Runnable {
/**
* Method run.
+ *
* @see java.lang.Runnable#run()
*/
@Override
diff --git a/src/main/java/fr/xephi/authme/process/unregister/AsyncronousUnregister.java b/src/main/java/fr/xephi/authme/process/unregister/AsyncronousUnregister.java
index 80c34835c..1dffbc1ae 100644
--- a/src/main/java/fr/xephi/authme/process/unregister/AsyncronousUnregister.java
+++ b/src/main/java/fr/xephi/authme/process/unregister/AsyncronousUnregister.java
@@ -1,13 +1,5 @@
package fr.xephi.authme.process.unregister;
-import java.security.NoSuchAlgorithmException;
-
-import org.bukkit.entity.Player;
-import org.bukkit.potion.PotionEffect;
-import org.bukkit.potion.PotionEffectType;
-import org.bukkit.scheduler.BukkitScheduler;
-import org.bukkit.scheduler.BukkitTask;
-
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerCache;
@@ -20,6 +12,13 @@ import fr.xephi.authme.task.MessageTask;
import fr.xephi.authme.task.TimeoutTask;
import fr.xephi.authme.util.Utils;
import fr.xephi.authme.util.Utils.GroupType;
+import org.bukkit.entity.Player;
+import org.bukkit.potion.PotionEffect;
+import org.bukkit.potion.PotionEffectType;
+import org.bukkit.scheduler.BukkitScheduler;
+import org.bukkit.scheduler.BukkitTask;
+
+import java.security.NoSuchAlgorithmException;
/**
*/
@@ -27,21 +26,22 @@ public class AsyncronousUnregister {
protected Player player;
protected String name;
+ protected String password;
+ protected boolean force;
private AuthMe plugin;
private Messages m = Messages.getInstance();
- protected String password;
- protected boolean force;
- private JsonCache playerCache;
+ private JsonCache playerCache;
/**
* Constructor for AsyncronousUnregister.
- * @param player Player
+ *
+ * @param player Player
* @param password String
- * @param force boolean
- * @param plugin AuthMe
+ * @param force boolean
+ * @param plugin AuthMe
*/
public AsyncronousUnregister(Player player, String password,
- boolean force, AuthMe plugin) {
+ boolean force, AuthMe plugin) {
this.player = player;
this.password = password;
this.force = force;
@@ -52,8 +52,9 @@ public class AsyncronousUnregister {
/**
* Method getIp.
-
- * @return String */
+ *
+ * @return String
+ */
protected String getIp() {
return plugin.getIP(player);
}
diff --git a/src/main/java/fr/xephi/authme/security/HashAlgorithm.java b/src/main/java/fr/xephi/authme/security/HashAlgorithm.java
index db3fb202f..dc22a2aa5 100644
--- a/src/main/java/fr/xephi/authme/security/HashAlgorithm.java
+++ b/src/main/java/fr/xephi/authme/security/HashAlgorithm.java
@@ -39,6 +39,7 @@ public enum HashAlgorithm {
/**
* Constructor for HashAlgorithm.
+ *
* @param classe Class>
*/
HashAlgorithm(Class> classe) {
@@ -47,8 +48,9 @@ public enum HashAlgorithm {
/**
* Method getclasse.
-
- * @return Class> */
+ *
+ * @return Class>
+ */
public Class> getclasse() {
return classe;
}
diff --git a/src/main/java/fr/xephi/authme/security/PasswordSecurity.java b/src/main/java/fr/xephi/authme/security/PasswordSecurity.java
index 1bca5e18f..453db7fb8 100644
--- a/src/main/java/fr/xephi/authme/security/PasswordSecurity.java
+++ b/src/main/java/fr/xephi/authme/security/PasswordSecurity.java
@@ -1,33 +1,32 @@
package fr.xephi.authme.security;
-import java.math.BigInteger;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.security.SecureRandom;
-import java.util.HashMap;
-
-import org.bukkit.Bukkit;
-
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.events.PasswordEncryptionEvent;
import fr.xephi.authme.security.crypts.BCRYPT;
import fr.xephi.authme.security.crypts.EncryptionMethod;
import fr.xephi.authme.settings.Settings;
+import org.bukkit.Bukkit;
+
+import java.math.BigInteger;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.security.SecureRandom;
+import java.util.HashMap;
/**
*/
public class PasswordSecurity {
- private static SecureRandom rnd = new SecureRandom();
public static HashMap userSalt = new HashMap<>();
+ private static SecureRandom rnd = new SecureRandom();
/**
* Method createSalt.
+ *
* @param length int
-
-
- * @return String * @throws NoSuchAlgorithmException */
+ * @return String * @throws NoSuchAlgorithmException
+ */
public static String createSalt(int length)
throws NoSuchAlgorithmException {
byte[] msg = new byte[40];
@@ -40,12 +39,12 @@ public class PasswordSecurity {
/**
* Method getHash.
- * @param alg HashAlgorithm
- * @param password String
+ *
+ * @param alg HashAlgorithm
+ * @param password String
* @param playerName String
-
-
- * @return String * @throws NoSuchAlgorithmException */
+ * @return String * @throws NoSuchAlgorithmException
+ */
public static String getHash(HashAlgorithm alg, String password,
String playerName) throws NoSuchAlgorithmException {
EncryptionMethod method;
@@ -143,12 +142,12 @@ public class PasswordSecurity {
/**
* Method comparePasswordWithHash.
- * @param password String
- * @param hash String
+ *
+ * @param password String
+ * @param hash String
* @param playerName String
-
-
- * @return boolean * @throws NoSuchAlgorithmException */
+ * @return boolean * @throws NoSuchAlgorithmException
+ */
public static boolean comparePasswordWithHash(String password, String hash,
String playerName) throws NoSuchAlgorithmException {
HashAlgorithm algo = Settings.getPasswordHash;
@@ -181,12 +180,12 @@ public class PasswordSecurity {
/**
* Method compareWithAllEncryptionMethod.
- * @param password String
- * @param hash String
+ *
+ * @param password String
+ * @param hash String
* @param playerName String
-
-
- * @return boolean * @throws NoSuchAlgorithmException */
+ * @return boolean * @throws NoSuchAlgorithmException
+ */
private static boolean compareWithAllEncryptionMethod(String password,
String hash, String playerName) throws NoSuchAlgorithmException {
for (HashAlgorithm algo : HashAlgorithm.values()) {
diff --git a/src/main/java/fr/xephi/authme/security/RandomString.java b/src/main/java/fr/xephi/authme/security/RandomString.java
index fec71b719..d9f58bfc8 100644
--- a/src/main/java/fr/xephi/authme/security/RandomString.java
+++ b/src/main/java/fr/xephi/authme/security/RandomString.java
@@ -4,7 +4,6 @@ import java.util.Calendar;
import java.util.Random;
/**
- *
* @author Xephi59
* @version $Revision: 1.0 $
*/
@@ -25,6 +24,7 @@ public class RandomString {
/**
* Constructor for RandomString.
+ *
* @param length int
*/
public RandomString(int length) {
@@ -36,8 +36,9 @@ public class RandomString {
/**
* Method nextString.
-
- * @return String */
+ *
+ * @return String
+ */
public String nextString() {
for (int idx = 0; idx < buf.length; ++idx)
buf[idx] = chars[random.nextInt(chars.length)];
diff --git a/src/main/java/fr/xephi/authme/security/crypts/BCRYPT.java b/src/main/java/fr/xephi/authme/security/crypts/BCRYPT.java
index 0eb79b332..b0c1adbe2 100644
--- a/src/main/java/fr/xephi/authme/security/crypts/BCRYPT.java
+++ b/src/main/java/fr/xephi/authme/security/crypts/BCRYPT.java
@@ -92,8 +92,6 @@ public class BCRYPT implements EncryptionMethod {
*
* @param d the byte array to encode
* @param len the number of bytes to encode
-
-
* @return base64-encoded string * @throws IllegalArgumentException if the length is invalid * @throws IllegalArgumentException
*/
private static String encode_base64(byte d[], int len)
@@ -134,8 +132,8 @@ public class BCRYPT implements EncryptionMethod {
* range-checking againt conversion table
*
* @param x the base64-encoded value
-
- * @return the decoded value of x */
+ * @return the decoded value of x
+ */
private static byte char64(char x) {
if ((int) x > index_64.length)
return -1;
@@ -149,8 +147,6 @@ public class BCRYPT implements EncryptionMethod {
*
* @param s the string to decode
* @param maxolen the maximum number of bytes to decode
-
-
* @return an array containing the decoded bytes * @throws IllegalArgumentException if maxolen is invalid * @throws IllegalArgumentException
*/
private static byte[] decode_base64(String s, int maxolen)
@@ -194,6 +190,178 @@ public class BCRYPT implements EncryptionMethod {
return ret;
}
+ /**
+ * Cycically extract a word of key material
+ *
+ * @param data the string to extract the data from
+ * @param offp a "pointer" (as a one-entry array) to the current offset into
+ * data
+ * @return the next word of material from data
+ */
+ private static int streamtoword(byte data[], int offp[]) {
+ int i;
+ int word = 0;
+ int off = offp[0];
+
+ for (i = 0; i < 4; i++) {
+ word = (word << 8) | (data[off] & 0xff);
+ off = (off + 1) % data.length;
+ }
+
+ offp[0] = off;
+ return word;
+ }
+
+ /**
+ * Hash a password using the OpenBSD bcrypt scheme
+ *
+ * @param password the password to hash
+ * @param salt the salt to hash with (perhaps generated using BCrypt.gensalt)
+ * @return the hashed password
+ */
+ public static String hashpw(String password, String salt) {
+ BCRYPT B;
+ String real_salt;
+ byte passwordb[], saltb[], hashed[];
+ char minor = (char) 0;
+ int rounds, off = 0;
+ StringBuffer rs = new StringBuffer();
+
+ if (salt.charAt(0) != '$' || salt.charAt(1) != '2')
+ throw new IllegalArgumentException("Invalid salt version");
+ if (salt.charAt(2) == '$')
+ off = 3;
+ else {
+ minor = salt.charAt(2);
+ if (minor < 'a' || minor > 'z' || salt.charAt(3) != '$')
+ throw new IllegalArgumentException("Invalid salt revision");
+ off = 4;
+ }
+
+ // Extract number of rounds
+ if (salt.charAt(off + 2) > '$')
+ throw new IllegalArgumentException("Missing salt rounds");
+ rounds = Integer.parseInt(salt.substring(off, off + 2));
+
+ real_salt = salt.substring(off + 3, off + 25);
+ try {
+ passwordb = (password + (minor >= 'a' ? "\000" : "")).getBytes("UTF-8");
+ } catch (UnsupportedEncodingException uee) {
+ throw new AssertionError("UTF-8 is not supported");
+ }
+
+ saltb = decode_base64(real_salt, BCRYPT_SALT_LEN);
+
+ B = new BCRYPT();
+ hashed = B.crypt_raw(passwordb, saltb, rounds);
+
+ rs.append("$2");
+ if (minor >= 'a')
+ rs.append(minor);
+ rs.append('$');
+ if (rounds < 10)
+ rs.append('0');
+ rs.append(Integer.toString(rounds));
+ rs.append('$');
+ rs.append(encode_base64(saltb, saltb.length));
+ rs.append(encode_base64(hashed, bf_crypt_ciphertext.length * 4 - 1));
+ return rs.toString();
+ }
+
+ /**
+ * Generate a salt for use with the BCrypt.hashpw() method
+ *
+ * @param log_rounds the log2 of the number of rounds of hashing to apply - the
+ * work factor therefore increases as 2**log_rounds.
+ * @param random an instance of SecureRandom to use
+ * @return an encoded salt value
+ */
+ public static String gensalt(int log_rounds, SecureRandom random) {
+ StringBuffer rs = new StringBuffer();
+ byte rnd[] = new byte[BCRYPT_SALT_LEN];
+
+ random.nextBytes(rnd);
+
+ rs.append("$2a$");
+ if (log_rounds < 10)
+ rs.append('0');
+ rs.append(Integer.toString(log_rounds));
+ rs.append('$');
+ rs.append(encode_base64(rnd, rnd.length));
+ return rs.toString();
+ }
+
+ /**
+ * Generate a salt for use with the BCrypt.hashpw() method
+ *
+ * @param log_rounds the log2 of the number of rounds of hashing to apply - the
+ * work factor therefore increases as 2**log_rounds.
+ * @return an encoded salt value
+ */
+ public static String gensalt(int log_rounds) {
+ return gensalt(log_rounds, new SecureRandom());
+ }
+
+ /**
+ * Generate a salt for use with the BCrypt.hashpw() method, selecting a
+ * reasonable default for the number of hashing rounds to apply
+ *
+ * @return an encoded salt value
+ */
+ public static String gensalt() {
+ return gensalt(GENSALT_DEFAULT_LOG2_ROUNDS);
+ }
+
+ /**
+ * Check that a plaintext password matches a previously hashed one
+ *
+ * @param plaintext the plaintext password to verify
+ * @param hashed the previously-hashed password
+ * @return true if the passwords match, false otherwise
+ */
+ public static boolean checkpw(String plaintext, String hashed) {
+ return (hashed.compareTo(hashpw(plaintext, hashed)) == 0);
+ }
+
+ /**
+ * Check that a text password matches a previously hashed one with the
+ * specified number of rounds using recursion
+ *
+ * @param text plaintext or hashed text
+ * @param hashed the previously-hashed password
+ * @param rounds number of rounds to hash the password
+ * @return boolean
+ */
+ public static boolean checkpw(String text, String hashed, int rounds) {
+ boolean matched = false;
+
+ if (rounds > 0) {
+ String hash = hashpw(text, hashed);
+
+ if (rounds > 1) {
+ matched = checkpw(hash, hashed, rounds - 1);
+ } else {
+ matched = hash.compareTo(hashed) == 0;
+ }
+ } else {
+ matched = text.compareTo(hashed) == 0;
+ }
+
+ return matched;
+ }
+
+ /**
+ * Method getDoubleHash.
+ *
+ * @param text String
+ * @param salt String
+ * @return String
+ */
+ public static String getDoubleHash(String text, String salt) {
+ String hash = hashpw(text, salt);
+ return hashpw(text, hash);
+ }
+
/**
* Blowfish encipher a single 64-bit block encoded as two 32-bit halves
*
@@ -223,28 +391,6 @@ public class BCRYPT implements EncryptionMethod {
lr[off + 1] = l;
}
- /**
- * Cycically extract a word of key material
- *
- * @param data the string to extract the data from
- * @param offp a "pointer" (as a one-entry array) to the current offset into
- * data
-
- * @return the next word of material from data */
- private static int streamtoword(byte data[], int offp[]) {
- int i;
- int word = 0;
- int off = offp[0];
-
- for (i = 0; i < 4; i++) {
- word = (word << 8) | (data[off] & 0xff);
- off = (off + 1) % data.length;
- }
-
- offp[0] = off;
- return word;
- }
-
/**
* Initialise the Blowfish key schedule
*/
@@ -321,8 +467,8 @@ public class BCRYPT implements EncryptionMethod {
* @param salt the binary salt to hash with the password
* @param log_rounds the binary logarithm of the number of rounds of hashing to
* apply
-
- * @return an array containing the binary hashed password */
+ * @return an array containing the binary hashed password
+ */
private byte[] crypt_raw(byte password[], byte salt[], int log_rounds) {
int rounds, i, j;
int cdata[] = bf_crypt_ciphertext.clone();
@@ -357,154 +503,14 @@ public class BCRYPT implements EncryptionMethod {
return ret;
}
- /**
- * Hash a password using the OpenBSD bcrypt scheme
- *
- * @param password the password to hash
- * @param salt the salt to hash with (perhaps generated using BCrypt.gensalt)
-
- * @return the hashed password */
- public static String hashpw(String password, String salt) {
- BCRYPT B;
- String real_salt;
- byte passwordb[], saltb[], hashed[];
- char minor = (char) 0;
- int rounds, off = 0;
- StringBuffer rs = new StringBuffer();
-
- if (salt.charAt(0) != '$' || salt.charAt(1) != '2')
- throw new IllegalArgumentException("Invalid salt version");
- if (salt.charAt(2) == '$')
- off = 3;
- else {
- minor = salt.charAt(2);
- if (minor < 'a' || minor > 'z' || salt.charAt(3) != '$')
- throw new IllegalArgumentException("Invalid salt revision");
- off = 4;
- }
-
- // Extract number of rounds
- if (salt.charAt(off + 2) > '$')
- throw new IllegalArgumentException("Missing salt rounds");
- rounds = Integer.parseInt(salt.substring(off, off + 2));
-
- real_salt = salt.substring(off + 3, off + 25);
- try {
- passwordb = (password + (minor >= 'a' ? "\000" : "")).getBytes("UTF-8");
- } catch (UnsupportedEncodingException uee) {
- throw new AssertionError("UTF-8 is not supported");
- }
-
- saltb = decode_base64(real_salt, BCRYPT_SALT_LEN);
-
- B = new BCRYPT();
- hashed = B.crypt_raw(passwordb, saltb, rounds);
-
- rs.append("$2");
- if (minor >= 'a')
- rs.append(minor);
- rs.append('$');
- if (rounds < 10)
- rs.append('0');
- rs.append(Integer.toString(rounds));
- rs.append('$');
- rs.append(encode_base64(saltb, saltb.length));
- rs.append(encode_base64(hashed, bf_crypt_ciphertext.length * 4 - 1));
- return rs.toString();
- }
-
- /**
- * Generate a salt for use with the BCrypt.hashpw() method
- *
- * @param log_rounds the log2 of the number of rounds of hashing to apply - the
- * work factor therefore increases as 2**log_rounds.
- * @param random an instance of SecureRandom to use
-
- * @return an encoded salt value */
- public static String gensalt(int log_rounds, SecureRandom random) {
- StringBuffer rs = new StringBuffer();
- byte rnd[] = new byte[BCRYPT_SALT_LEN];
-
- random.nextBytes(rnd);
-
- rs.append("$2a$");
- if (log_rounds < 10)
- rs.append('0');
- rs.append(Integer.toString(log_rounds));
- rs.append('$');
- rs.append(encode_base64(rnd, rnd.length));
- return rs.toString();
- }
-
- /**
- * Generate a salt for use with the BCrypt.hashpw() method
- *
- * @param log_rounds the log2 of the number of rounds of hashing to apply - the
- * work factor therefore increases as 2**log_rounds.
-
- * @return an encoded salt value */
- public static String gensalt(int log_rounds) {
- return gensalt(log_rounds, new SecureRandom());
- }
-
- /**
- * Generate a salt for use with the BCrypt.hashpw() method, selecting a
- * reasonable default for the number of hashing rounds to apply
- *
-
- * @return an encoded salt value */
- public static String gensalt() {
- return gensalt(GENSALT_DEFAULT_LOG2_ROUNDS);
- }
-
- /**
- * Check that a plaintext password matches a previously hashed one
- *
- * @param plaintext the plaintext password to verify
- * @param hashed the previously-hashed password
-
- * @return true if the passwords match, false otherwise */
- public static boolean checkpw(String plaintext, String hashed) {
- return (hashed.compareTo(hashpw(plaintext, hashed)) == 0);
- }
-
- /**
- * Check that a text password matches a previously hashed one with the
- * specified number of rounds using recursion
- *
- * @param text plaintext or hashed text
- * @param hashed the previously-hashed password
- * @param rounds number of rounds to hash the password
-
-
- * @return boolean */
- public static boolean checkpw(String text, String hashed, int rounds) {
- boolean matched = false;
-
- if (rounds > 0) {
- String hash = hashpw(text, hashed);
-
- if (rounds > 1) {
- matched = checkpw(hash, hashed, rounds - 1);
- } else {
- matched = hash.compareTo(hashed) == 0;
- }
- } else {
- matched = text.compareTo(hashed) == 0;
- }
-
- return matched;
- }
-
/**
* Method getHash.
+ *
* @param password String
- * @param salt String
- * @param name String
-
-
-
- * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */
+ * @param salt String
+ * @param name String
+ * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
+ */
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
@@ -513,27 +519,15 @@ public class BCRYPT implements EncryptionMethod {
/**
* Method comparePassword.
- * @param hash String
- * @param password String
+ *
+ * @param hash String
+ * @param password String
* @param playerName String
-
-
-
- * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */
+ * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
+ */
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
return checkpw(password, hash);
}
-
- /**
- * Method getDoubleHash.
- * @param text String
- * @param salt String
-
- * @return String */
- public static String getDoubleHash(String text, String salt) {
- String hash = hashpw(text, salt);
- return hashpw(text, hash);
- }
}
diff --git a/src/main/java/fr/xephi/authme/security/crypts/BCRYPT2Y.java b/src/main/java/fr/xephi/authme/security/crypts/BCRYPT2Y.java
index ddee2cd80..4db8d8c6f 100644
--- a/src/main/java/fr/xephi/authme/security/crypts/BCRYPT2Y.java
+++ b/src/main/java/fr/xephi/authme/security/crypts/BCRYPT2Y.java
@@ -8,13 +8,12 @@ public class BCRYPT2Y implements EncryptionMethod {
/**
* Method getHash.
+ *
* @param password String
- * @param salt String
- * @param name String
-
-
-
- * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */
+ * @param salt String
+ * @param name String
+ * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
+ */
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
@@ -25,16 +24,15 @@ public class BCRYPT2Y implements EncryptionMethod {
/**
* Method comparePassword.
- * @param hash String
- * @param password String
+ *
+ * @param hash String
+ * @param password String
* @param playerName String
-
-
-
- * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */
+ * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
+ */
@Override
public boolean comparePassword(String hash, String password,
- String playerName) throws NoSuchAlgorithmException {
+ String playerName) throws NoSuchAlgorithmException {
String ok = hash.substring(0, 29);
if (ok.length() != 29)
return false;
diff --git a/src/main/java/fr/xephi/authme/security/crypts/CRAZYCRYPT1.java b/src/main/java/fr/xephi/authme/security/crypts/CRAZYCRYPT1.java
index 86e640c6f..ac890a883 100644
--- a/src/main/java/fr/xephi/authme/security/crypts/CRAZYCRYPT1.java
+++ b/src/main/java/fr/xephi/authme/security/crypts/CRAZYCRYPT1.java
@@ -8,18 +8,32 @@ import java.security.NoSuchAlgorithmException;
*/
public class CRAZYCRYPT1 implements EncryptionMethod {
+ private static final char[] CRYPTCHARS = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
protected final Charset charset = Charset.forName("UTF-8");
- private static final char[] CRYPTCHARS = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
+
+ /**
+ * Method byteArrayToHexString.
+ *
+ * @param args byte[]String * @return String
+ */
+
+ public static String byteArrayToHexString(final byte... args) {
+ final char[] chars = new char[args.length * 2];
+ for (int i = 0; i < args.length; i++) {
+ chars[i * 2] = CRYPTCHARS[(args[i] >> 4) & 0xF];
+ chars[i * 2 + 1] = CRYPTCHARS[(args[i]) & 0xF];
+ }
+ return new String(chars);
+ }
/**
* Method getHash.
+ *
* @param password String
- * @param salt String
- * @param name String
-
-
-
- * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */
+ * @param salt String
+ * @param name String
+ * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
+ */
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
@@ -32,29 +46,18 @@ public class CRAZYCRYPT1 implements EncryptionMethod {
return null;
}
}
-/**
+
+ /**
* Method comparePassword.
- * @param hash String
- * @param password String
+ *
+ * @param hash String
+ * @param password String
* @param playerName Stringooleaneptiontring) * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
*/
-
+
@Override
public boolean comparePassword(String hash, String password,
- String playerName) throws NoSuchAlgorithmException {
+ String playerName) throws NoSuchAlgorithmException {
return hash.equals(getHash(password, null, playerName));
}
-/**
- * Method byteArrayToHexString.
- * @param args byte[]String * @return String
- */
-
- public static String byteArrayToHexString(final byte... args) {
- final char[] chars = new char[args.length * 2];
- for (int i = 0; i < args.length; i++) {
- chars[i * 2] = CRYPTCHARS[(args[i] >> 4) & 0xF];
- chars[i * 2 + 1] = CRYPTCHARS[(args[i]) & 0xF];
- }
- return new String(chars);
- }
}
diff --git a/src/main/java/fr/xephi/authme/security/crypts/CryptPBKDF2.java b/src/main/java/fr/xephi/authme/security/crypts/CryptPBKDF2.java
index 9b1bc7795..e6bc7c036 100644
--- a/src/main/java/fr/xephi/authme/security/crypts/CryptPBKDF2.java
+++ b/src/main/java/fr/xephi/authme/security/crypts/CryptPBKDF2.java
@@ -1,23 +1,22 @@
package fr.xephi.authme.security.crypts;
-import java.security.NoSuchAlgorithmException;
-
import fr.xephi.authme.security.pbkdf2.PBKDF2Engine;
import fr.xephi.authme.security.pbkdf2.PBKDF2Parameters;
+import java.security.NoSuchAlgorithmException;
+
/**
*/
public class CryptPBKDF2 implements EncryptionMethod {
/**
* Method getHash.
+ *
* @param password String
- * @param salt String
- * @param name String
-
-
-
- * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */
+ * @param salt String
+ * @param name String
+ * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
+ */
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
@@ -30,16 +29,15 @@ public class CryptPBKDF2 implements EncryptionMethod {
/**
* Method comparePassword.
- * @param hash String
- * @param password String
+ *
+ * @param hash String
+ * @param password String
* @param playerName String
-
-
-
- * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */
+ * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
+ */
@Override
public boolean comparePassword(String hash, String password,
- String playerName) throws NoSuchAlgorithmException {
+ String playerName) throws NoSuchAlgorithmException {
String[] line = hash.split("\\$");
String salt = line[2];
String derivedKey = line[3];
diff --git a/src/main/java/fr/xephi/authme/security/crypts/CryptPBKDF2Django.java b/src/main/java/fr/xephi/authme/security/crypts/CryptPBKDF2Django.java
index 7c70909de..13aaf49f8 100644
--- a/src/main/java/fr/xephi/authme/security/crypts/CryptPBKDF2Django.java
+++ b/src/main/java/fr/xephi/authme/security/crypts/CryptPBKDF2Django.java
@@ -1,25 +1,23 @@
package fr.xephi.authme.security.crypts;
-import java.security.NoSuchAlgorithmException;
-
-import javax.xml.bind.DatatypeConverter;
-
import fr.xephi.authme.security.pbkdf2.PBKDF2Engine;
import fr.xephi.authme.security.pbkdf2.PBKDF2Parameters;
+import javax.xml.bind.DatatypeConverter;
+import java.security.NoSuchAlgorithmException;
+
/**
*/
public class CryptPBKDF2Django implements EncryptionMethod {
/**
* Method getHash.
+ *
* @param password String
- * @param salt String
- * @param name String
-
-
-
- * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */
+ * @param salt String
+ * @param name String
+ * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
+ */
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
@@ -32,13 +30,12 @@ public class CryptPBKDF2Django implements EncryptionMethod {
/**
* Method comparePassword.
- * @param hash String
- * @param password String
+ *
+ * @param hash String
+ * @param password String
* @param playerName String
-
-
-
- * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */
+ * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
+ */
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
diff --git a/src/main/java/fr/xephi/authme/security/crypts/DOUBLEMD5.java b/src/main/java/fr/xephi/authme/security/crypts/DOUBLEMD5.java
index 7f089be84..486ffbae2 100644
--- a/src/main/java/fr/xephi/authme/security/crypts/DOUBLEMD5.java
+++ b/src/main/java/fr/xephi/authme/security/crypts/DOUBLEMD5.java
@@ -8,42 +8,12 @@ import java.security.NoSuchAlgorithmException;
*/
public class DOUBLEMD5 implements EncryptionMethod {
- /**
- * Method getHash.
- * @param password String
- * @param salt String
- * @param name String
-
-
-
- * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */
- @Override
- public String getHash(String password, String salt, String name)
- throws NoSuchAlgorithmException {
- return getMD5(getMD5(password));
- }
-
- /**
- * Method comparePassword.
- * @param hash String
- * @param password String
- * @param playerName String
-
-
-
- * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */
- @Override
- public boolean comparePassword(String hash, String password,
- String playerName) throws NoSuchAlgorithmException {
- return hash.equals(getHash(password, "", ""));
- }
-
/**
* Method getMD5.
+ *
* @param message String
-
-
- * @return String * @throws NoSuchAlgorithmException */
+ * @return String * @throws NoSuchAlgorithmException
+ */
private static String getMD5(String message)
throws NoSuchAlgorithmException {
MessageDigest md5 = MessageDigest.getInstance("MD5");
@@ -53,4 +23,32 @@ public class DOUBLEMD5 implements EncryptionMethod {
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1, digest));
}
+ /**
+ * Method getHash.
+ *
+ * @param password String
+ * @param salt String
+ * @param name String
+ * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
+ */
+ @Override
+ public String getHash(String password, String salt, String name)
+ throws NoSuchAlgorithmException {
+ return getMD5(getMD5(password));
+ }
+
+ /**
+ * Method comparePassword.
+ *
+ * @param hash String
+ * @param password String
+ * @param playerName String
+ * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
+ */
+ @Override
+ public boolean comparePassword(String hash, String password,
+ String playerName) throws NoSuchAlgorithmException {
+ return hash.equals(getHash(password, "", ""));
+ }
+
}
diff --git a/src/main/java/fr/xephi/authme/security/crypts/EncryptionMethod.java b/src/main/java/fr/xephi/authme/security/crypts/EncryptionMethod.java
index 829c786e8..e56e5ecd9 100644
--- a/src/main/java/fr/xephi/authme/security/crypts/EncryptionMethod.java
+++ b/src/main/java/fr/xephi/authme/security/crypts/EncryptionMethod.java
@@ -13,6 +13,7 @@ import java.security.NoSuchAlgorithmException;
*
* The comparePassword is called when we need to match password (/login usually)
*
+ *
* @author Gabriele
* @version $Revision: 1.0 $
*/
@@ -20,12 +21,9 @@ public interface EncryptionMethod {
/**
* @param password
- * @param salt
- * (can be an other data like playerName;salt , playerName,
- * etc... for customs methods)
-
-
- * @param name String
+ * @param salt (can be an other data like playerName;salt , playerName,
+ * etc... for customs methods)
+ * @param name String
* @return Hashing password * @throws NoSuchAlgorithmException * @throws NoSuchAlgorithmException
*/
String getHash(String password, String salt, String name)
@@ -35,8 +33,6 @@ public interface EncryptionMethod {
* @param hash
* @param password
* @param playerName
-
-
* @return true if password match, false else * @throws NoSuchAlgorithmException * @throws NoSuchAlgorithmException
*/
boolean comparePassword(String hash, String password, String playerName)
diff --git a/src/main/java/fr/xephi/authme/security/crypts/IPB3.java b/src/main/java/fr/xephi/authme/security/crypts/IPB3.java
index 7d8ca944f..857c3fef3 100644
--- a/src/main/java/fr/xephi/authme/security/crypts/IPB3.java
+++ b/src/main/java/fr/xephi/authme/security/crypts/IPB3.java
@@ -1,52 +1,21 @@
package fr.xephi.authme.security.crypts;
+import fr.xephi.authme.AuthMe;
+
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
-import fr.xephi.authme.AuthMe;
-
/**
*/
public class IPB3 implements EncryptionMethod {
- /**
- * Method getHash.
- * @param password String
- * @param salt String
- * @param name String
-
-
-
- * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */
- @Override
- public String getHash(String password, String salt, String name)
- throws NoSuchAlgorithmException {
- return getMD5(getMD5(salt) + getMD5(password));
- }
-
- /**
- * Method comparePassword.
- * @param hash String
- * @param password String
- * @param playerName String
-
-
-
- * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */
- @Override
- public boolean comparePassword(String hash, String password,
- String playerName) throws NoSuchAlgorithmException {
- String salt = AuthMe.getInstance().database.getAuth(playerName).getSalt();
- return hash.equals(getHash(password, salt, playerName));
- }
-
/**
* Method getMD5.
+ *
* @param message String
-
-
- * @return String * @throws NoSuchAlgorithmException */
+ * @return String * @throws NoSuchAlgorithmException
+ */
private static String getMD5(String message)
throws NoSuchAlgorithmException {
MessageDigest md5 = MessageDigest.getInstance("MD5");
@@ -55,4 +24,33 @@ public class IPB3 implements EncryptionMethod {
byte[] digest = md5.digest();
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1, digest));
}
+
+ /**
+ * Method getHash.
+ *
+ * @param password String
+ * @param salt String
+ * @param name String
+ * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
+ */
+ @Override
+ public String getHash(String password, String salt, String name)
+ throws NoSuchAlgorithmException {
+ return getMD5(getMD5(salt) + getMD5(password));
+ }
+
+ /**
+ * Method comparePassword.
+ *
+ * @param hash String
+ * @param password String
+ * @param playerName String
+ * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
+ */
+ @Override
+ public boolean comparePassword(String hash, String password,
+ String playerName) throws NoSuchAlgorithmException {
+ String salt = AuthMe.getInstance().database.getAuth(playerName).getSalt();
+ return hash.equals(getHash(password, salt, playerName));
+ }
}
diff --git a/src/main/java/fr/xephi/authme/security/crypts/JOOMLA.java b/src/main/java/fr/xephi/authme/security/crypts/JOOMLA.java
index f43d15f24..73fbd3bdc 100644
--- a/src/main/java/fr/xephi/authme/security/crypts/JOOMLA.java
+++ b/src/main/java/fr/xephi/authme/security/crypts/JOOMLA.java
@@ -8,43 +8,12 @@ import java.security.NoSuchAlgorithmException;
*/
public class JOOMLA implements EncryptionMethod {
- /**
- * Method getHash.
- * @param password String
- * @param salt String
- * @param name String
-
-
-
- * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */
- @Override
- public String getHash(String password, String salt, String name)
- throws NoSuchAlgorithmException {
- return getMD5(password + salt) + ":" + salt;
- }
-
- /**
- * Method comparePassword.
- * @param hash String
- * @param password String
- * @param playerName String
-
-
-
- * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */
- @Override
- public boolean comparePassword(String hash, String password,
- String playerName) throws NoSuchAlgorithmException {
- String salt = hash.split(":")[1];
- return hash.equals(getMD5(password + salt) + ":" + salt);
- }
-
/**
* Method getMD5.
+ *
* @param message String
-
-
- * @return String * @throws NoSuchAlgorithmException */
+ * @return String * @throws NoSuchAlgorithmException
+ */
private static String getMD5(String message)
throws NoSuchAlgorithmException {
MessageDigest md5 = MessageDigest.getInstance("MD5");
@@ -53,4 +22,33 @@ public class JOOMLA implements EncryptionMethod {
byte[] digest = md5.digest();
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1, digest));
}
+
+ /**
+ * Method getHash.
+ *
+ * @param password String
+ * @param salt String
+ * @param name String
+ * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
+ */
+ @Override
+ public String getHash(String password, String salt, String name)
+ throws NoSuchAlgorithmException {
+ return getMD5(password + salt) + ":" + salt;
+ }
+
+ /**
+ * Method comparePassword.
+ *
+ * @param hash String
+ * @param password String
+ * @param playerName String
+ * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
+ */
+ @Override
+ public boolean comparePassword(String hash, String password,
+ String playerName) throws NoSuchAlgorithmException {
+ String salt = hash.split(":")[1];
+ return hash.equals(getMD5(password + salt) + ":" + salt);
+ }
}
diff --git a/src/main/java/fr/xephi/authme/security/crypts/MD5.java b/src/main/java/fr/xephi/authme/security/crypts/MD5.java
index 7caf5ba3d..af94098bd 100644
--- a/src/main/java/fr/xephi/authme/security/crypts/MD5.java
+++ b/src/main/java/fr/xephi/authme/security/crypts/MD5.java
@@ -8,42 +8,12 @@ import java.security.NoSuchAlgorithmException;
*/
public class MD5 implements EncryptionMethod {
- /**
- * Method getHash.
- * @param password String
- * @param salt String
- * @param name String
-
-
-
- * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */
- @Override
- public String getHash(String password, String salt, String name)
- throws NoSuchAlgorithmException {
- return getMD5(password);
- }
-
- /**
- * Method comparePassword.
- * @param hash String
- * @param password String
- * @param playerName String
-
-
-
- * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */
- @Override
- public boolean comparePassword(String hash, String password,
- String playerName) throws NoSuchAlgorithmException {
- return hash.equals(getHash(password, "", ""));
- }
-
/**
* Method getMD5.
+ *
* @param message String
-
-
- * @return String * @throws NoSuchAlgorithmException */
+ * @return String * @throws NoSuchAlgorithmException
+ */
private static String getMD5(String message)
throws NoSuchAlgorithmException {
MessageDigest md5 = MessageDigest.getInstance("MD5");
@@ -52,4 +22,32 @@ public class MD5 implements EncryptionMethod {
byte[] digest = md5.digest();
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1, digest));
}
+
+ /**
+ * Method getHash.
+ *
+ * @param password String
+ * @param salt String
+ * @param name String
+ * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
+ */
+ @Override
+ public String getHash(String password, String salt, String name)
+ throws NoSuchAlgorithmException {
+ return getMD5(password);
+ }
+
+ /**
+ * Method comparePassword.
+ *
+ * @param hash String
+ * @param password String
+ * @param playerName String
+ * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
+ */
+ @Override
+ public boolean comparePassword(String hash, String password,
+ String playerName) throws NoSuchAlgorithmException {
+ return hash.equals(getHash(password, "", ""));
+ }
}
diff --git a/src/main/java/fr/xephi/authme/security/crypts/MD5VB.java b/src/main/java/fr/xephi/authme/security/crypts/MD5VB.java
index ecb8a78c8..ab2878f4c 100644
--- a/src/main/java/fr/xephi/authme/security/crypts/MD5VB.java
+++ b/src/main/java/fr/xephi/authme/security/crypts/MD5VB.java
@@ -8,43 +8,12 @@ import java.security.NoSuchAlgorithmException;
*/
public class MD5VB implements EncryptionMethod {
- /**
- * Method getHash.
- * @param password String
- * @param salt String
- * @param name String
-
-
-
- * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */
- @Override
- public String getHash(String password, String salt, String name)
- throws NoSuchAlgorithmException {
- return "$MD5vb$" + salt + "$" + getMD5(getMD5(password) + salt);
- }
-
- /**
- * Method comparePassword.
- * @param hash String
- * @param password String
- * @param playerName String
-
-
-
- * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */
- @Override
- public boolean comparePassword(String hash, String password,
- String playerName) throws NoSuchAlgorithmException {
- String[] line = hash.split("\\$");
- return hash.equals(getHash(password, line[2], ""));
- }
-
/**
* Method getMD5.
+ *
* @param message String
-
-
- * @return String * @throws NoSuchAlgorithmException */
+ * @return String * @throws NoSuchAlgorithmException
+ */
private static String getMD5(String message)
throws NoSuchAlgorithmException {
MessageDigest md5 = MessageDigest.getInstance("MD5");
@@ -54,4 +23,33 @@ public class MD5VB implements EncryptionMethod {
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1, digest));
}
+ /**
+ * Method getHash.
+ *
+ * @param password String
+ * @param salt String
+ * @param name String
+ * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
+ */
+ @Override
+ public String getHash(String password, String salt, String name)
+ throws NoSuchAlgorithmException {
+ return "$MD5vb$" + salt + "$" + getMD5(getMD5(password) + salt);
+ }
+
+ /**
+ * Method comparePassword.
+ *
+ * @param hash String
+ * @param password String
+ * @param playerName String
+ * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
+ */
+ @Override
+ public boolean comparePassword(String hash, String password,
+ String playerName) throws NoSuchAlgorithmException {
+ String[] line = hash.split("\\$");
+ return hash.equals(getHash(password, line[2], ""));
+ }
+
}
diff --git a/src/main/java/fr/xephi/authme/security/crypts/MYBB.java b/src/main/java/fr/xephi/authme/security/crypts/MYBB.java
index 02a362c3e..0cae271fa 100644
--- a/src/main/java/fr/xephi/authme/security/crypts/MYBB.java
+++ b/src/main/java/fr/xephi/authme/security/crypts/MYBB.java
@@ -1,52 +1,21 @@
package fr.xephi.authme.security.crypts;
+import fr.xephi.authme.AuthMe;
+
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
-import fr.xephi.authme.AuthMe;
-
/**
*/
public class MYBB implements EncryptionMethod {
- /**
- * Method getHash.
- * @param password String
- * @param salt String
- * @param name String
-
-
-
- * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */
- @Override
- public String getHash(String password, String salt, String name)
- throws NoSuchAlgorithmException {
- return getMD5(getMD5(salt) + getMD5(password));
- }
-
- /**
- * Method comparePassword.
- * @param hash String
- * @param password String
- * @param playerName String
-
-
-
- * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */
- @Override
- public boolean comparePassword(String hash, String password,
- String playerName) throws NoSuchAlgorithmException {
- String salt = AuthMe.getInstance().database.getAuth(playerName).getSalt();
- return hash.equals(getHash(password, salt, playerName));
- }
-
/**
* Method getMD5.
+ *
* @param message String
-
-
- * @return String * @throws NoSuchAlgorithmException */
+ * @return String * @throws NoSuchAlgorithmException
+ */
private static String getMD5(String message)
throws NoSuchAlgorithmException {
MessageDigest md5 = MessageDigest.getInstance("MD5");
@@ -55,4 +24,33 @@ public class MYBB implements EncryptionMethod {
byte[] digest = md5.digest();
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1, digest));
}
+
+ /**
+ * Method getHash.
+ *
+ * @param password String
+ * @param salt String
+ * @param name String
+ * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
+ */
+ @Override
+ public String getHash(String password, String salt, String name)
+ throws NoSuchAlgorithmException {
+ return getMD5(getMD5(salt) + getMD5(password));
+ }
+
+ /**
+ * Method comparePassword.
+ *
+ * @param hash String
+ * @param password String
+ * @param playerName String
+ * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
+ */
+ @Override
+ public boolean comparePassword(String hash, String password,
+ String playerName) throws NoSuchAlgorithmException {
+ String salt = AuthMe.getInstance().database.getAuth(playerName).getSalt();
+ return hash.equals(getHash(password, salt, playerName));
+ }
}
diff --git a/src/main/java/fr/xephi/authme/security/crypts/PHPBB.java b/src/main/java/fr/xephi/authme/security/crypts/PHPBB.java
index ac06e32ea..58ebdc748 100644
--- a/src/main/java/fr/xephi/authme/security/crypts/PHPBB.java
+++ b/src/main/java/fr/xephi/authme/security/crypts/PHPBB.java
@@ -17,12 +17,79 @@ public class PHPBB implements EncryptionMethod {
private String itoa64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+ /**
+ * Method md5.
+ *
+ * @param data String
+ * @return String
+ */
+ public static String md5(String data) {
+ try {
+ byte[] bytes = data.getBytes("ISO-8859-1");
+ MessageDigest md5er = MessageDigest.getInstance("MD5");
+ byte[] hash = md5er.digest(bytes);
+ return bytes2hex(hash);
+ } catch (GeneralSecurityException | UnsupportedEncodingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Method hexToInt.
+ *
+ * @param ch char
+ * @return int
+ */
+ static int hexToInt(char ch) {
+ if (ch >= '0' && ch <= '9')
+ return ch - '0';
+ ch = Character.toUpperCase(ch);
+ if (ch >= 'A' && ch <= 'F')
+ return ch - 'A' + 0xA;
+ throw new IllegalArgumentException("Not a hex character: " + ch);
+ }
+
+ /**
+ * Method bytes2hex.
+ *
+ * @param bytes byte[]
+ * @return String
+ */
+ private static String bytes2hex(byte[] bytes) {
+ 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);
+ }
+ return r.toString();
+ }
+
+ /**
+ * Method pack.
+ *
+ * @param hex String
+ * @return String
+ */
+ static String pack(String hex) {
+ StringBuilder buf = new StringBuilder();
+ for (int i = 0; i < hex.length(); i += 2) {
+ char c1 = hex.charAt(i);
+ char c2 = hex.charAt(i + 1);
+ char packed = (char) (hexToInt(c1) * 16 + hexToInt(c2));
+ buf.append(packed);
+ }
+ return buf.toString();
+ }
+
/**
* Method phpbb_hash.
+ *
* @param password String
- * @param salt String
-
- * @return String */
+ * @param salt String
+ * @return String
+ */
public String phpbb_hash(String password, String salt) {
String random_state = salt;
StringBuilder random = new StringBuilder();
@@ -40,21 +107,23 @@ public class PHPBB implements EncryptionMethod {
/**
* Method _hash_gensalt_private.
- * @param input String
+ *
+ * @param input String
* @param itoa64 String
-
- * @return String */
+ * @return String
+ */
private String _hash_gensalt_private(String input, String itoa64) {
return _hash_gensalt_private(input, itoa64, 6);
}
/**
* Method _hash_gensalt_private.
- * @param input String
- * @param itoa64 String
+ *
+ * @param input String
+ * @param itoa64 String
* @param iteration_count_log2 int
-
- * @return String */
+ * @return String
+ */
private String _hash_gensalt_private(String input, String itoa64,
int iteration_count_log2) {
if (iteration_count_log2 < 4 || iteration_count_log2 > 31) {
@@ -68,10 +137,11 @@ public class PHPBB implements EncryptionMethod {
/**
* Encode hash
+ *
* @param input String
* @param count int
-
- * @return String */
+ * @return String
+ */
private String _hash_encode64(String input, int count) {
StringBuilder output = new StringBuilder();
int i = 0;
@@ -95,10 +165,11 @@ public class PHPBB implements EncryptionMethod {
/**
* Method _hash_crypt_private.
+ *
* @param password String
- * @param setting String
-
- * @return String */
+ * @param setting String
+ * @return String
+ */
String _hash_crypt_private(String password, String setting) {
String output = "*";
if (!setting.substring(0, 3).equals("$H$"))
@@ -122,87 +193,25 @@ public class PHPBB implements EncryptionMethod {
/**
* Method phpbb_check_hash.
+ *
* @param password String
- * @param hash String
-
- * @return boolean */
+ * @param hash String
+ * @return boolean
+ */
public boolean phpbb_check_hash(String password, String hash) {
if (hash.length() == 34)
return _hash_crypt_private(password, hash).equals(hash);
else return md5(password).equals(hash);
}
- /**
- * Method md5.
- * @param data String
-
- * @return String */
- public static String md5(String data) {
- try {
- byte[] bytes = data.getBytes("ISO-8859-1");
- MessageDigest md5er = MessageDigest.getInstance("MD5");
- byte[] hash = md5er.digest(bytes);
- return bytes2hex(hash);
- } catch (GeneralSecurityException | UnsupportedEncodingException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Method hexToInt.
- * @param ch char
-
- * @return int */
- static int hexToInt(char ch) {
- if (ch >= '0' && ch <= '9')
- return ch - '0';
- ch = Character.toUpperCase(ch);
- if (ch >= 'A' && ch <= 'F')
- return ch - 'A' + 0xA;
- throw new IllegalArgumentException("Not a hex character: " + ch);
- }
-
- /**
- * Method bytes2hex.
- * @param bytes byte[]
-
- * @return String */
- private static String bytes2hex(byte[] bytes) {
- 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);
- }
- return r.toString();
- }
-
- /**
- * Method pack.
- * @param hex String
-
- * @return String */
- static String pack(String hex) {
- StringBuilder buf = new StringBuilder();
- for (int i = 0; i < hex.length(); i += 2) {
- char c1 = hex.charAt(i);
- char c2 = hex.charAt(i + 1);
- char packed = (char) (hexToInt(c1) * 16 + hexToInt(c2));
- buf.append(packed);
- }
- return buf.toString();
- }
-
/**
* Method getHash.
+ *
* @param password String
- * @param salt String
- * @param name String
-
-
-
- * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */
+ * @param salt String
+ * @param name String
+ * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
+ */
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
@@ -211,13 +220,12 @@ public class PHPBB implements EncryptionMethod {
/**
* Method comparePassword.
- * @param hash String
- * @param password String
+ *
+ * @param hash String
+ * @param password String
* @param playerName String
-
-
-
- * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */
+ * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
+ */
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
diff --git a/src/main/java/fr/xephi/authme/security/crypts/PHPFUSION.java b/src/main/java/fr/xephi/authme/security/crypts/PHPFUSION.java
index b9d938a8f..54e6cd66a 100644
--- a/src/main/java/fr/xephi/authme/security/crypts/PHPFUSION.java
+++ b/src/main/java/fr/xephi/authme/security/crypts/PHPFUSION.java
@@ -1,29 +1,42 @@
package fr.xephi.authme.security.crypts;
+import fr.xephi.authme.AuthMe;
+
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
-import javax.crypto.Mac;
-import javax.crypto.spec.SecretKeySpec;
-
-import fr.xephi.authme.AuthMe;
-
/**
*/
public class PHPFUSION implements EncryptionMethod {
+ /**
+ * Method getSHA1.
+ *
+ * @param message String
+ * @return String * @throws NoSuchAlgorithmException
+ */
+ private static String getSHA1(String message)
+ throws NoSuchAlgorithmException {
+ MessageDigest sha1 = MessageDigest.getInstance("SHA1");
+ sha1.reset();
+ sha1.update(message.getBytes());
+ byte[] digest = sha1.digest();
+ return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1, digest));
+ }
+
/**
* Method getHash.
+ *
* @param password String
- * @param salt String
- * @param name String
-
-
-
- * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */
+ * @param salt String
+ * @param name String
+ * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
+ */
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
@@ -53,33 +66,17 @@ public class PHPFUSION implements EncryptionMethod {
/**
* Method comparePassword.
- * @param hash String
- * @param password String
+ *
+ * @param hash String
+ * @param password String
* @param playerName String
-
-
-
- * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */
+ * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
+ */
@Override
public boolean comparePassword(String hash, String password,
- String playerName) throws NoSuchAlgorithmException {
+ String playerName) throws NoSuchAlgorithmException {
String salt = AuthMe.getInstance().database.getAuth(playerName).getSalt();
return hash.equals(getHash(password, salt, ""));
}
- /**
- * Method getSHA1.
- * @param message String
-
-
- * @return String * @throws NoSuchAlgorithmException */
- private static String getSHA1(String message)
- throws NoSuchAlgorithmException {
- MessageDigest sha1 = MessageDigest.getInstance("SHA1");
- sha1.reset();
- sha1.update(message.getBytes());
- byte[] digest = sha1.digest();
- return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1, digest));
- }
-
}
diff --git a/src/main/java/fr/xephi/authme/security/crypts/PLAINTEXT.java b/src/main/java/fr/xephi/authme/security/crypts/PLAINTEXT.java
index 94f4fe5fd..afb6dde95 100644
--- a/src/main/java/fr/xephi/authme/security/crypts/PLAINTEXT.java
+++ b/src/main/java/fr/xephi/authme/security/crypts/PLAINTEXT.java
@@ -8,13 +8,12 @@ public class PLAINTEXT implements EncryptionMethod {
/**
* Method getHash.
+ *
* @param password String
- * @param salt String
- * @param name String
-
-
-
- * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */
+ * @param salt String
+ * @param name String
+ * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
+ */
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
@@ -23,16 +22,15 @@ public class PLAINTEXT implements EncryptionMethod {
/**
* Method comparePassword.
- * @param hash String
- * @param password String
+ *
+ * @param hash String
+ * @param password String
* @param playerName String
-
-
-
- * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */
+ * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
+ */
@Override
public boolean comparePassword(String hash, String password,
- String playerName) throws NoSuchAlgorithmException {
+ String playerName) throws NoSuchAlgorithmException {
return hash.equals(password);
}
diff --git a/src/main/java/fr/xephi/authme/security/crypts/ROYALAUTH.java b/src/main/java/fr/xephi/authme/security/crypts/ROYALAUTH.java
index e9b9e1e98..ad3901e49 100644
--- a/src/main/java/fr/xephi/authme/security/crypts/ROYALAUTH.java
+++ b/src/main/java/fr/xephi/authme/security/crypts/ROYALAUTH.java
@@ -9,13 +9,12 @@ public class ROYALAUTH implements EncryptionMethod {
/**
* Method getHash.
+ *
* @param password String
- * @param salt String
- * @param name String
-
-
-
- * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */
+ * @param salt String
+ * @param name String
+ * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
+ */
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
@@ -26,11 +25,11 @@ public class ROYALAUTH implements EncryptionMethod {
/**
* Method hash.
+ *
* @param password String
- * @param salt String
-
-
- * @return String * @throws NoSuchAlgorithmException */
+ * @param salt String
+ * @return String * @throws NoSuchAlgorithmException
+ */
public String hash(String password, String salt)
throws NoSuchAlgorithmException {
MessageDigest md = MessageDigest.getInstance("SHA-512");
@@ -44,16 +43,15 @@ public class ROYALAUTH implements EncryptionMethod {
/**
* Method comparePassword.
- * @param hash String
- * @param password String
+ *
+ * @param hash String
+ * @param password String
* @param playerName String
-
-
-
- * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */
+ * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
+ */
@Override
public boolean comparePassword(String hash, String password,
- String playerName) throws NoSuchAlgorithmException {
+ String playerName) throws NoSuchAlgorithmException {
return hash.equalsIgnoreCase(getHash(password, "", ""));
}
diff --git a/src/main/java/fr/xephi/authme/security/crypts/SALTED2MD5.java b/src/main/java/fr/xephi/authme/security/crypts/SALTED2MD5.java
index f90f6907b..f71018ace 100644
--- a/src/main/java/fr/xephi/authme/security/crypts/SALTED2MD5.java
+++ b/src/main/java/fr/xephi/authme/security/crypts/SALTED2MD5.java
@@ -1,52 +1,21 @@
package fr.xephi.authme.security.crypts;
+import fr.xephi.authme.AuthMe;
+
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
-import fr.xephi.authme.AuthMe;
-
/**
*/
public class SALTED2MD5 implements EncryptionMethod {
- /**
- * Method getHash.
- * @param password String
- * @param salt String
- * @param name String
-
-
-
- * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */
- @Override
- public String getHash(String password, String salt, String name)
- throws NoSuchAlgorithmException {
- return getMD5(getMD5(password) + salt);
- }
-
- /**
- * Method comparePassword.
- * @param hash String
- * @param password String
- * @param playerName String
-
-
-
- * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */
- @Override
- public boolean comparePassword(String hash, String password,
- String playerName) throws NoSuchAlgorithmException {
- String salt = AuthMe.getInstance().database.getAuth(playerName).getSalt();
- return hash.equals(getMD5(getMD5(password) + salt));
- }
-
/**
* Method getMD5.
+ *
* @param message String
-
-
- * @return String * @throws NoSuchAlgorithmException */
+ * @return String * @throws NoSuchAlgorithmException
+ */
private static String getMD5(String message)
throws NoSuchAlgorithmException {
MessageDigest md5 = MessageDigest.getInstance("MD5");
@@ -55,4 +24,33 @@ public class SALTED2MD5 implements EncryptionMethod {
byte[] digest = md5.digest();
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1, digest));
}
+
+ /**
+ * Method getHash.
+ *
+ * @param password String
+ * @param salt String
+ * @param name String
+ * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
+ */
+ @Override
+ public String getHash(String password, String salt, String name)
+ throws NoSuchAlgorithmException {
+ return getMD5(getMD5(password) + salt);
+ }
+
+ /**
+ * Method comparePassword.
+ *
+ * @param hash String
+ * @param password String
+ * @param playerName String
+ * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
+ */
+ @Override
+ public boolean comparePassword(String hash, String password,
+ String playerName) throws NoSuchAlgorithmException {
+ String salt = AuthMe.getInstance().database.getAuth(playerName).getSalt();
+ return hash.equals(getMD5(getMD5(password) + salt));
+ }
}
diff --git a/src/main/java/fr/xephi/authme/security/crypts/SALTEDSHA512.java b/src/main/java/fr/xephi/authme/security/crypts/SALTEDSHA512.java
index cd2b4aac4..dcacb63ce 100644
--- a/src/main/java/fr/xephi/authme/security/crypts/SALTEDSHA512.java
+++ b/src/main/java/fr/xephi/authme/security/crypts/SALTEDSHA512.java
@@ -1,52 +1,21 @@
package fr.xephi.authme.security.crypts;
+import fr.xephi.authme.AuthMe;
+
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
-import fr.xephi.authme.AuthMe;
-
/**
*/
public class SALTEDSHA512 implements EncryptionMethod {
- /**
- * Method getHash.
- * @param password String
- * @param salt String
- * @param name String
-
-
-
- * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */
- @Override
- public String getHash(String password, String salt, String name)
- throws NoSuchAlgorithmException {
- return getSHA512(password + salt);
- }
-
- /**
- * Method comparePassword.
- * @param hash String
- * @param password String
- * @param playerName String
-
-
-
- * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */
- @Override
- public boolean comparePassword(String hash, String password,
- String playerName) throws NoSuchAlgorithmException {
- String salt = AuthMe.getInstance().database.getAuth(playerName).getSalt();
- return hash.equals(getHash(password, salt, ""));
- }
-
/**
* Method getSHA512.
+ *
* @param message String
-
-
- * @return String * @throws NoSuchAlgorithmException */
+ * @return String * @throws NoSuchAlgorithmException
+ */
private static String getSHA512(String message)
throws NoSuchAlgorithmException {
MessageDigest sha512 = MessageDigest.getInstance("SHA-512");
@@ -55,4 +24,33 @@ public class SALTEDSHA512 implements EncryptionMethod {
byte[] digest = sha512.digest();
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1, digest));
}
+
+ /**
+ * Method getHash.
+ *
+ * @param password String
+ * @param salt String
+ * @param name String
+ * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
+ */
+ @Override
+ public String getHash(String password, String salt, String name)
+ throws NoSuchAlgorithmException {
+ return getSHA512(password + salt);
+ }
+
+ /**
+ * Method comparePassword.
+ *
+ * @param hash String
+ * @param password String
+ * @param playerName String
+ * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
+ */
+ @Override
+ public boolean comparePassword(String hash, String password,
+ String playerName) throws NoSuchAlgorithmException {
+ String salt = AuthMe.getInstance().database.getAuth(playerName).getSalt();
+ return hash.equals(getHash(password, salt, ""));
+ }
}
diff --git a/src/main/java/fr/xephi/authme/security/crypts/SHA1.java b/src/main/java/fr/xephi/authme/security/crypts/SHA1.java
index ae1fab0a4..7d1a48a6b 100644
--- a/src/main/java/fr/xephi/authme/security/crypts/SHA1.java
+++ b/src/main/java/fr/xephi/authme/security/crypts/SHA1.java
@@ -8,42 +8,12 @@ import java.security.NoSuchAlgorithmException;
*/
public class SHA1 implements EncryptionMethod {
- /**
- * Method getHash.
- * @param password String
- * @param salt String
- * @param name String
-
-
-
- * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */
- @Override
- public String getHash(String password, String salt, String name)
- throws NoSuchAlgorithmException {
- return getSHA1(password);
- }
-
- /**
- * Method comparePassword.
- * @param hash String
- * @param password String
- * @param playerName String
-
-
-
- * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */
- @Override
- public boolean comparePassword(String hash, String password,
- String playerName) throws NoSuchAlgorithmException {
- return hash.equals(getHash(password, "", ""));
- }
-
/**
* Method getSHA1.
+ *
* @param message String
-
-
- * @return String * @throws NoSuchAlgorithmException */
+ * @return String * @throws NoSuchAlgorithmException
+ */
private static String getSHA1(String message)
throws NoSuchAlgorithmException {
MessageDigest sha1 = MessageDigest.getInstance("SHA1");
@@ -53,4 +23,32 @@ public class SHA1 implements EncryptionMethod {
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1, digest));
}
+ /**
+ * Method getHash.
+ *
+ * @param password String
+ * @param salt String
+ * @param name String
+ * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
+ */
+ @Override
+ public String getHash(String password, String salt, String name)
+ throws NoSuchAlgorithmException {
+ return getSHA1(password);
+ }
+
+ /**
+ * Method comparePassword.
+ *
+ * @param hash String
+ * @param password String
+ * @param playerName String
+ * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
+ */
+ @Override
+ public boolean comparePassword(String hash, String password,
+ String playerName) throws NoSuchAlgorithmException {
+ return hash.equals(getHash(password, "", ""));
+ }
+
}
diff --git a/src/main/java/fr/xephi/authme/security/crypts/SHA256.java b/src/main/java/fr/xephi/authme/security/crypts/SHA256.java
index 11d53e168..b0ddfa565 100644
--- a/src/main/java/fr/xephi/authme/security/crypts/SHA256.java
+++ b/src/main/java/fr/xephi/authme/security/crypts/SHA256.java
@@ -8,43 +8,12 @@ import java.security.NoSuchAlgorithmException;
*/
public class SHA256 implements EncryptionMethod {
- /**
- * Method getHash.
- * @param password String
- * @param salt String
- * @param name String
-
-
-
- * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */
- @Override
- public String getHash(String password, String salt, String name)
- throws NoSuchAlgorithmException {
- return "$SHA$" + salt + "$" + getSHA256(getSHA256(password) + salt);
- }
-
- /**
- * Method comparePassword.
- * @param hash String
- * @param password String
- * @param playerName String
-
-
-
- * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */
- @Override
- public boolean comparePassword(String hash, String password,
- String playerName) throws NoSuchAlgorithmException {
- String[] line = hash.split("\\$");
- return hash.equals(getHash(password, line[2], ""));
- }
-
/**
* Method getSHA256.
+ *
* @param message String
-
-
- * @return String * @throws NoSuchAlgorithmException */
+ * @return String * @throws NoSuchAlgorithmException
+ */
private static String getSHA256(String message)
throws NoSuchAlgorithmException {
MessageDigest sha256 = MessageDigest.getInstance("SHA-256");
@@ -54,4 +23,33 @@ public class SHA256 implements EncryptionMethod {
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1, digest));
}
+ /**
+ * Method getHash.
+ *
+ * @param password String
+ * @param salt String
+ * @param name String
+ * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
+ */
+ @Override
+ public String getHash(String password, String salt, String name)
+ throws NoSuchAlgorithmException {
+ return "$SHA$" + salt + "$" + getSHA256(getSHA256(password) + salt);
+ }
+
+ /**
+ * Method comparePassword.
+ *
+ * @param hash String
+ * @param password String
+ * @param playerName String
+ * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
+ */
+ @Override
+ public boolean comparePassword(String hash, String password,
+ String playerName) throws NoSuchAlgorithmException {
+ String[] line = hash.split("\\$");
+ return hash.equals(getHash(password, line[2], ""));
+ }
+
}
diff --git a/src/main/java/fr/xephi/authme/security/crypts/SHA512.java b/src/main/java/fr/xephi/authme/security/crypts/SHA512.java
index a44d9367b..a6ccd6153 100644
--- a/src/main/java/fr/xephi/authme/security/crypts/SHA512.java
+++ b/src/main/java/fr/xephi/authme/security/crypts/SHA512.java
@@ -8,42 +8,12 @@ import java.security.NoSuchAlgorithmException;
*/
public class SHA512 implements EncryptionMethod {
- /**
- * Method getHash.
- * @param password String
- * @param salt String
- * @param name String
-
-
-
- * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */
- @Override
- public String getHash(String password, String salt, String name)
- throws NoSuchAlgorithmException {
- return getSHA512(password);
- }
-
- /**
- * Method comparePassword.
- * @param hash String
- * @param password String
- * @param playerName String
-
-
-
- * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */
- @Override
- public boolean comparePassword(String hash, String password,
- String playerName) throws NoSuchAlgorithmException {
- return hash.equals(getHash(password, "", ""));
- }
-
/**
* Method getSHA512.
+ *
* @param message String
-
-
- * @return String * @throws NoSuchAlgorithmException */
+ * @return String * @throws NoSuchAlgorithmException
+ */
private static String getSHA512(String message)
throws NoSuchAlgorithmException {
MessageDigest sha512 = MessageDigest.getInstance("SHA-512");
@@ -52,4 +22,32 @@ public class SHA512 implements EncryptionMethod {
byte[] digest = sha512.digest();
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1, digest));
}
+
+ /**
+ * Method getHash.
+ *
+ * @param password String
+ * @param salt String
+ * @param name String
+ * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
+ */
+ @Override
+ public String getHash(String password, String salt, String name)
+ throws NoSuchAlgorithmException {
+ return getSHA512(password);
+ }
+
+ /**
+ * Method comparePassword.
+ *
+ * @param hash String
+ * @param password String
+ * @param playerName String
+ * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
+ */
+ @Override
+ public boolean comparePassword(String hash, String password,
+ String playerName) throws NoSuchAlgorithmException {
+ return hash.equals(getHash(password, "", ""));
+ }
}
diff --git a/src/main/java/fr/xephi/authme/security/crypts/SMF.java b/src/main/java/fr/xephi/authme/security/crypts/SMF.java
index 8ee0cbe08..ce15e030e 100644
--- a/src/main/java/fr/xephi/authme/security/crypts/SMF.java
+++ b/src/main/java/fr/xephi/authme/security/crypts/SMF.java
@@ -8,42 +8,12 @@ import java.security.NoSuchAlgorithmException;
*/
public class SMF implements EncryptionMethod {
- /**
- * Method getHash.
- * @param password String
- * @param salt String
- * @param name String
-
-
-
- * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */
- @Override
- public String getHash(String password, String salt, String name)
- throws NoSuchAlgorithmException {
- return getSHA1(name.toLowerCase() + password);
- }
-
- /**
- * Method comparePassword.
- * @param hash String
- * @param password String
- * @param playerName String
-
-
-
- * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */
- @Override
- public boolean comparePassword(String hash, String password,
- String playerName) throws NoSuchAlgorithmException {
- return hash.equals(getHash(password, null, playerName));
- }
-
/**
* Method getSHA1.
+ *
* @param message String
-
-
- * @return String * @throws NoSuchAlgorithmException */
+ * @return String * @throws NoSuchAlgorithmException
+ */
private static String getSHA1(String message)
throws NoSuchAlgorithmException {
MessageDigest sha1 = MessageDigest.getInstance("SHA1");
@@ -52,4 +22,32 @@ public class SMF implements EncryptionMethod {
byte[] digest = sha1.digest();
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1, digest));
}
+
+ /**
+ * Method getHash.
+ *
+ * @param password String
+ * @param salt String
+ * @param name String
+ * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
+ */
+ @Override
+ public String getHash(String password, String salt, String name)
+ throws NoSuchAlgorithmException {
+ return getSHA1(name.toLowerCase() + password);
+ }
+
+ /**
+ * Method comparePassword.
+ *
+ * @param hash String
+ * @param password String
+ * @param playerName String
+ * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
+ */
+ @Override
+ public boolean comparePassword(String hash, String password,
+ String playerName) throws NoSuchAlgorithmException {
+ return hash.equals(getHash(password, null, playerName));
+ }
}
diff --git a/src/main/java/fr/xephi/authme/security/crypts/WBB3.java b/src/main/java/fr/xephi/authme/security/crypts/WBB3.java
index 4a5cdef20..1d966423d 100644
--- a/src/main/java/fr/xephi/authme/security/crypts/WBB3.java
+++ b/src/main/java/fr/xephi/authme/security/crypts/WBB3.java
@@ -1,52 +1,21 @@
package fr.xephi.authme.security.crypts;
+import fr.xephi.authme.AuthMe;
+
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
-import fr.xephi.authme.AuthMe;
-
/**
*/
public class WBB3 implements EncryptionMethod {
- /**
- * Method getHash.
- * @param password String
- * @param salt String
- * @param name String
-
-
-
- * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */
- @Override
- public String getHash(String password, String salt, String name)
- throws NoSuchAlgorithmException {
- return getSHA1(salt.concat(getSHA1(salt.concat(getSHA1(password)))));
- }
-
- /**
- * Method comparePassword.
- * @param hash String
- * @param password String
- * @param playerName String
-
-
-
- * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */
- @Override
- public boolean comparePassword(String hash, String password,
- String playerName) throws NoSuchAlgorithmException {
- String salt = AuthMe.getInstance().database.getAuth(playerName).getSalt();
- return hash.equals(getHash(password, salt, ""));
- }
-
/**
* Method getSHA1.
+ *
* @param message String
-
-
- * @return String * @throws NoSuchAlgorithmException */
+ * @return String * @throws NoSuchAlgorithmException
+ */
private static String getSHA1(String message)
throws NoSuchAlgorithmException {
MessageDigest sha1 = MessageDigest.getInstance("SHA1");
@@ -55,4 +24,33 @@ public class WBB3 implements EncryptionMethod {
byte[] digest = sha1.digest();
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1, digest));
}
+
+ /**
+ * Method getHash.
+ *
+ * @param password String
+ * @param salt String
+ * @param name String
+ * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
+ */
+ @Override
+ public String getHash(String password, String salt, String name)
+ throws NoSuchAlgorithmException {
+ return getSHA1(salt.concat(getSHA1(salt.concat(getSHA1(password)))));
+ }
+
+ /**
+ * Method comparePassword.
+ *
+ * @param hash String
+ * @param password String
+ * @param playerName String
+ * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
+ */
+ @Override
+ public boolean comparePassword(String hash, String password,
+ String playerName) throws NoSuchAlgorithmException {
+ String salt = AuthMe.getInstance().database.getAuth(playerName).getSalt();
+ return hash.equals(getHash(password, salt, ""));
+ }
}
diff --git a/src/main/java/fr/xephi/authme/security/crypts/WBB4.java b/src/main/java/fr/xephi/authme/security/crypts/WBB4.java
index ab43c65ac..ebe79438c 100644
--- a/src/main/java/fr/xephi/authme/security/crypts/WBB4.java
+++ b/src/main/java/fr/xephi/authme/security/crypts/WBB4.java
@@ -8,13 +8,12 @@ public class WBB4 implements EncryptionMethod {
/**
* Method getHash.
+ *
* @param password String
- * @param salt String
- * @param name String
-
-
-
- * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */
+ * @param salt String
+ * @param name String
+ * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
+ */
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
@@ -23,16 +22,15 @@ public class WBB4 implements EncryptionMethod {
/**
* Method comparePassword.
- * @param hash String
- * @param password String
+ *
+ * @param hash String
+ * @param password String
* @param playerName String
-
-
-
- * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */
+ * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
+ */
@Override
public boolean comparePassword(String hash, String password,
- String playerName) throws NoSuchAlgorithmException {
+ String playerName) throws NoSuchAlgorithmException {
return BCRYPT.checkpw(password, hash, 2);
}
diff --git a/src/main/java/fr/xephi/authme/security/crypts/WHIRLPOOL.java b/src/main/java/fr/xephi/authme/security/crypts/WHIRLPOOL.java
index f8cf09ee6..596aafe8d 100644
--- a/src/main/java/fr/xephi/authme/security/crypts/WHIRLPOOL.java
+++ b/src/main/java/fr/xephi/authme/security/crypts/WHIRLPOOL.java
@@ -2,63 +2,61 @@ package fr.xephi.authme.security.crypts;
/**
* The Whirlpool hashing function.
- *
- *
+ *
+ *
* References
- *
- *
+ *
+ *
* The Whirlpool algorithm was developed by Paulo S. L. M. Barreto and Vincent Rijmen.
- *
+ *
* See P.S.L.M. Barreto, V. Rijmen, ``The Whirlpool hashing function,'' First
* NESSIE workshop, 2000 (tweaked version, 2003),
*
- *
+ *
* @author Paulo S.L.M. Barreto
* @author Vincent Rijmen.
- *
* @version 3.0 (2003.03.12)
- *
- * ====================================================================
- * =========
- *
- * Differences from version 2.1:
- *
- * - Suboptimal diffusion matrix replaced by cir(1, 1, 4, 1, 8, 5, 2,
- * 9).
- *
- * ====================================================================
- * =========
- *
- * Differences from version 2.0:
- *
- * - Generation of ISO/IEC 10118-3 test vectors. - Bug fix: nonzero
- * carry was ignored when tallying the data length (this bug apparently
- * only manifested itself when feeding data in pieces rather than in a
- * single chunk at once).
- *
- * Differences from version 1.0:
- *
- * - Original S-box replaced by the tweaked, hardware-efficient
- * version.
- *
- * ====================================================================
- * =========
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS
- * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
+ *
+ * ====================================================================
+ * =========
+ *
+ * Differences from version 2.1:
+ *
+ * - Suboptimal diffusion matrix replaced by cir(1, 1, 4, 1, 8, 5, 2,
+ * 9).
+ *
+ * ====================================================================
+ * =========
+ *
+ * Differences from version 2.0:
+ *
+ * - Generation of ISO/IEC 10118-3 test vectors. - Bug fix: nonzero
+ * carry was ignored when tallying the data length (this bug apparently
+ * only manifested itself when feeding data in pieces rather than in a
+ * single chunk at once).
+ *
+ * Differences from version 1.0:
+ *
+ * - Original S-box replaced by the tweaked, hardware-efficient
+ * version.
+ *
+ * ====================================================================
+ * =========
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import java.security.NoSuchAlgorithmException;
@@ -166,6 +164,22 @@ public class WHIRLPOOL implements EncryptionMethod {
public WHIRLPOOL() {
}
+ /**
+ * Method display.
+ * @param array byte[]
+
+ * @return String */
+ protected static String display(byte[] array) {
+ char[] val = new char[2 * array.length];
+ String hex = "0123456789ABCDEF";
+ for (int i = 0; i < array.length; i++) {
+ int b = array[i] & 0xff;
+ val[2 * i] = hex.charAt(b >>> 4);
+ val[2 * i + 1] = hex.charAt(b & 15);
+ }
+ return String.valueOf(val);
+ }
+
/**
* The core Whirlpool transform.
*/
@@ -232,12 +246,12 @@ public class WHIRLPOOL implements EncryptionMethod {
/**
* Delivers input data to the hashing algorithm.
- *
+ *
* @param source
* plaintext data to hash.
* @param sourceBits
* how many bits of plaintext to process.
- *
+ *
* This method maintains the invariant: bufferBits < 512
*/
public void NESSIEadd(byte[] source, long sourceBits) {
@@ -249,9 +263,9 @@ public class WHIRLPOOL implements EncryptionMethod {
* +-------+-------+-------+-------+-------+------- | bufferPos
*/
int sourcePos = 0; // index of leftmost source byte containing data (1
- // to 8 bits).
+ // to 8 bits).
int sourceGap = (8 - ((int) sourceBits & 7)) & 7; // space on
- // source[sourcePos].
+ // source[sourcePos].
int bufferRem = bufferBits & 7; // occupied bits on buffer[bufferPos].
int b;
// tally the length of the added data:
@@ -264,7 +278,7 @@ public class WHIRLPOOL implements EncryptionMethod {
}
// process data in chunks of 8 bits:
while (sourceBits > 8) { // at least source[sourcePos] and
- // source[sourcePos+1] contain data.
+ // source[sourcePos+1] contain data.
// take a byte from the source:
b = ((source[sourcePos] << sourceGap) & 0xff) | ((source[sourcePos + 1] & 0xff) >>> (8 - sourceGap));
if (b < 0 || b >= 256) {
@@ -289,7 +303,7 @@ public class WHIRLPOOL implements EncryptionMethod {
// furthermore, all data (if any is left) is in source[sourcePos].
if (sourceBits > 0) {
b = (source[sourcePos] << sourceGap) & 0xff; // bits are
- // left-justified on b.
+ // left-justified on b.
// process the remaining bits:
buffer[bufferPos] |= b >>> bufferRem;
} else {
@@ -319,7 +333,7 @@ public class WHIRLPOOL implements EncryptionMethod {
/**
* Get the hash value from the hashing state.
- *
+ *
* This method uses the invariant: bufferBits < 512
* @param digest byte[]
*/
@@ -360,10 +374,10 @@ public class WHIRLPOOL implements EncryptionMethod {
/**
* Delivers string input data to the hashing algorithm.
- *
+ *
* @param source
* plaintext data to hash (ASCII text string).
- *
+ *
* This method maintains the invariant: bufferBits < 512
*/
public void NESSIEadd(String source) {
@@ -376,30 +390,14 @@ public class WHIRLPOOL implements EncryptionMethod {
}
}
- /**
- * Method display.
- * @param array byte[]
-
- * @return String */
- protected static String display(byte[] array) {
- char[] val = new char[2 * array.length];
- String hex = "0123456789ABCDEF";
- for (int i = 0; i < array.length; i++) {
- int b = array[i] & 0xff;
- val[2 * i] = hex.charAt(b >>> 4);
- val[2 * i + 1] = hex.charAt(b & 15);
- }
- return String.valueOf(val);
- }
-
/**
* Method getHash.
* @param password String
* @param salt String
* @param name String
-
-
-
+
+
+
* @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */
@Override
public String getHash(String password, String salt, String name)
@@ -416,13 +414,13 @@ public class WHIRLPOOL implements EncryptionMethod {
* @param hash String
* @param password String
* @param playerName String
-
-
-
+
+
+
* @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */
@Override
public boolean comparePassword(String hash, String password,
- String playerName) throws NoSuchAlgorithmException {
+ String playerName) throws NoSuchAlgorithmException {
return hash.equals(getHash(password, "", ""));
}
}
diff --git a/src/main/java/fr/xephi/authme/security/crypts/WORDPRESS.java b/src/main/java/fr/xephi/authme/security/crypts/WORDPRESS.java
index 6c74b0b93..557c4bdd4 100644
--- a/src/main/java/fr/xephi/authme/security/crypts/WORDPRESS.java
+++ b/src/main/java/fr/xephi/authme/security/crypts/WORDPRESS.java
@@ -15,10 +15,11 @@ public class WORDPRESS implements EncryptionMethod {
/**
* Method encode64.
- * @param src byte[]
+ *
+ * @param src byte[]
* @param count int
-
- * @return String */
+ * @return String
+ */
private String encode64(byte[] src, int count) {
int i, value;
StringBuilder output = new StringBuilder();
@@ -55,10 +56,11 @@ public class WORDPRESS implements EncryptionMethod {
/**
* Method crypt.
+ *
* @param password String
- * @param setting String
-
- * @return String */
+ * @param setting String
+ * @return String
+ */
private String crypt(String password, String setting) {
String output = "*0";
if (((setting.length() < 2) ? setting : setting.substring(0, 2)).equalsIgnoreCase(output)) {
@@ -99,9 +101,10 @@ public class WORDPRESS implements EncryptionMethod {
/**
* Method gensaltPrivate.
+ *
* @param input byte[]
-
- * @return String */
+ * @return String
+ */
private String gensaltPrivate(byte[] input) {
String output = "$P$";
int iterationCountLog2 = 8;
@@ -112,9 +115,10 @@ public class WORDPRESS implements EncryptionMethod {
/**
* Method stringToUtf8.
+ *
* @param string String
-
- * @return byte[] */
+ * @return byte[]
+ */
private byte[] stringToUtf8(String string) {
try {
return string.getBytes("UTF-8");
@@ -125,13 +129,12 @@ public class WORDPRESS implements EncryptionMethod {
/**
* Method getHash.
+ *
* @param password String
- * @param salt String
- * @param name String
-
-
-
- * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */
+ * @param salt String
+ * @param name String
+ * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
+ */
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
@@ -142,16 +145,15 @@ public class WORDPRESS implements EncryptionMethod {
/**
* Method comparePassword.
- * @param hash String
- * @param password String
+ *
+ * @param hash String
+ * @param password String
* @param playerName String
-
-
-
- * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */
+ * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
+ */
@Override
public boolean comparePassword(String hash, String password,
- String playerName) throws NoSuchAlgorithmException {
+ String playerName) throws NoSuchAlgorithmException {
String comparedHash = crypt(password, hash);
return comparedHash.equals(hash);
}
diff --git a/src/main/java/fr/xephi/authme/security/crypts/XAUTH.java b/src/main/java/fr/xephi/authme/security/crypts/XAUTH.java
index 2254700f8..6848d2ea9 100644
--- a/src/main/java/fr/xephi/authme/security/crypts/XAUTH.java
+++ b/src/main/java/fr/xephi/authme/security/crypts/XAUTH.java
@@ -6,15 +6,29 @@ import java.security.NoSuchAlgorithmException;
*/
public class XAUTH implements EncryptionMethod {
+ /**
+ * Method getWhirlpool.
+ *
+ * @param message String
+ * @return String
+ */
+ public static String getWhirlpool(String message) {
+ WHIRLPOOL w = new WHIRLPOOL();
+ byte[] digest = new byte[WHIRLPOOL.DIGESTBYTES];
+ w.NESSIEinit();
+ w.NESSIEadd(message);
+ w.NESSIEfinalize(digest);
+ return WHIRLPOOL.display(digest);
+ }
+
/**
* Method getHash.
+ *
* @param password String
- * @param salt String
- * @param name String
-
-
-
- * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */
+ * @param salt String
+ * @param name String
+ * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
+ */
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
@@ -25,33 +39,18 @@ public class XAUTH implements EncryptionMethod {
/**
* Method comparePassword.
- * @param hash String
- * @param password String
+ *
+ * @param hash String
+ * @param password String
* @param playerName String
-
-
-
- * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */
+ * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
+ */
@Override
public boolean comparePassword(String hash, String password,
- String playerName) throws NoSuchAlgorithmException {
+ String playerName) throws NoSuchAlgorithmException {
int saltPos = (password.length() >= hash.length() ? hash.length() - 1 : password.length());
String salt = hash.substring(saltPos, saltPos + 12);
return hash.equals(getHash(password, salt, ""));
}
- /**
- * Method getWhirlpool.
- * @param message String
-
- * @return String */
- public static String getWhirlpool(String message) {
- WHIRLPOOL w = new WHIRLPOOL();
- byte[] digest = new byte[WHIRLPOOL.DIGESTBYTES];
- w.NESSIEinit();
- w.NESSIEadd(message);
- w.NESSIEfinalize(digest);
- return WHIRLPOOL.display(digest);
- }
-
}
diff --git a/src/main/java/fr/xephi/authme/security/crypts/XF.java b/src/main/java/fr/xephi/authme/security/crypts/XF.java
index c8f778db4..41d665ace 100644
--- a/src/main/java/fr/xephi/authme/security/crypts/XF.java
+++ b/src/main/java/fr/xephi/authme/security/crypts/XF.java
@@ -1,5 +1,7 @@
package fr.xephi.authme.security.crypts;
+import fr.xephi.authme.AuthMe;
+
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
@@ -7,21 +9,18 @@ import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import fr.xephi.authme.AuthMe;
-
/**
*/
public class XF implements EncryptionMethod {
/**
* Method getHash.
+ *
* @param password String
- * @param salt String
- * @param name String
-
-
-
- * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String) */
+ * @param salt String
+ * @param name String
+ * @return String * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
+ */
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
@@ -30,26 +29,25 @@ public class XF implements EncryptionMethod {
/**
* Method comparePassword.
- * @param hash String
- * @param password String
+ *
+ * @param hash String
+ * @param password String
* @param playerName String
-
-
-
- * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String) */
+ * @return boolean * @throws NoSuchAlgorithmException * @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
+ */
@Override
public boolean comparePassword(String hash, String password,
- String playerName) throws NoSuchAlgorithmException {
+ String playerName) throws NoSuchAlgorithmException {
String salt = AuthMe.getInstance().database.getAuth(playerName).getSalt();
return hash.equals(regmatch("\"hash\";.:..:\"(.*)\";.:.:\"salt\"", salt));
}
/**
* Method getSHA256.
+ *
* @param password String
-
-
- * @return String * @throws NoSuchAlgorithmException */
+ * @return String * @throws NoSuchAlgorithmException
+ */
public String getSHA256(String password) throws NoSuchAlgorithmException {
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(password.getBytes());
@@ -71,10 +69,11 @@ public class XF implements EncryptionMethod {
/**
* Method regmatch.
+ *
* @param pattern String
- * @param line String
-
- * @return String */
+ * @param line String
+ * @return String
+ */
public String regmatch(String pattern, String line) {
List allMatches = new ArrayList<>();
Matcher m = Pattern.compile(pattern).matcher(line);
diff --git a/src/main/java/fr/xephi/authme/security/pbkdf2/BinTools.java b/src/main/java/fr/xephi/authme/security/pbkdf2/BinTools.java
index b8c5a1989..d465bbc61 100644
--- a/src/main/java/fr/xephi/authme/security/pbkdf2/BinTools.java
+++ b/src/main/java/fr/xephi/authme/security/pbkdf2/BinTools.java
@@ -26,7 +26,7 @@ package fr.xephi.authme.security.pbkdf2;
* href="http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html"
* >http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
*
- *
+ *
* @author Matthias Gärtner
* @version 1.0
*/
@@ -36,12 +36,11 @@ public class BinTools {
/**
* Simple binary-to-hexadecimal conversion.
- *
- * @param b
- * Input bytes. May be null
.
-
+ *
+ * @param b Input bytes. May be null
.
* @return Hexadecimal representation of b. Uppercase A-F, two characters
- * per byte. Empty string on null
input. */
+ * per byte. Empty string on null
input.
+ */
public static String bin2hex(final byte[] b) {
if (b == null) {
return "";
@@ -57,14 +56,12 @@ public class BinTools {
/**
* Convert hex string to array of bytes.
- *
- * @param s
- * String containing hexadecimal digits. May be null
- * . On odd length leading zero will be assumed.
-
-
+ *
+ * @param s String containing hexadecimal digits. May be null
+ * . On odd length leading zero will be assumed.
* @return Array on bytes, non-null
. * @throws IllegalArgumentException
- * when string contains non-hex character */
+ * when string contains non-hex character
+ */
public static byte[] hex2bin(final String s) {
String m = s;
if (s == null) {
@@ -85,13 +82,11 @@ public class BinTools {
/**
* Convert hex digit to numerical value.
- *
- * @param c
- * 0-9, a-f, A-F allowd.
-
-
+ *
+ * @param c 0-9, a-f, A-F allowd.
* @return 0-15 * @throws IllegalArgumentException
- * on non-hex character */
+ * on non-hex character
+ */
public static int hex2bin(char c) {
if (c >= '0' && c <= '9') {
return (c - '0');
@@ -107,6 +102,7 @@ public class BinTools {
/**
* Method main.
+ *
* @param args String[]
*/
public static void main(String[] args) {
diff --git a/src/main/java/fr/xephi/authme/security/pbkdf2/MacBasedPRF.java b/src/main/java/fr/xephi/authme/security/pbkdf2/MacBasedPRF.java
index 9a7cc0bcd..0332003b2 100644
--- a/src/main/java/fr/xephi/authme/security/pbkdf2/MacBasedPRF.java
+++ b/src/main/java/fr/xephi/authme/security/pbkdf2/MacBasedPRF.java
@@ -1,15 +1,14 @@
package fr.xephi.authme.security.pbkdf2;
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
-import javax.crypto.Mac;
-import javax.crypto.spec.SecretKeySpec;
-
/**
* Default PRF implementation based on standard javax.crypt.Mac mechanisms.
- *
+ *
*
*
* A free Java implementation of Password Based Key Derivation Function 2 as
@@ -52,8 +51,7 @@ public class MacBasedPRF implements PRF {
/**
* Create Mac-based Pseudo Random Function.
*
- * @param macAlgorithm
- * Mac algorithm to use, i.e. HMacSHA1 or HMacMD5.
+ * @param macAlgorithm Mac algorithm to use, i.e. HMacSHA1 or HMacMD5.
*/
public MacBasedPRF(String macAlgorithm) {
this.macAlgorithm = macAlgorithm;
@@ -67,8 +65,9 @@ public class MacBasedPRF implements PRF {
/**
* Constructor for MacBasedPRF.
+ *
* @param macAlgorithm String
- * @param provider String
+ * @param provider String
*/
public MacBasedPRF(String macAlgorithm, String provider) {
this.macAlgorithm = macAlgorithm;
@@ -82,10 +81,10 @@ public class MacBasedPRF implements PRF {
/**
* Method doFinal.
+ *
* @param M byte[]
-
-
- * @return byte[] * @see fr.xephi.authme.security.pbkdf2.PRF#doFinal(byte[]) */
+ * @return byte[] * @see fr.xephi.authme.security.pbkdf2.PRF#doFinal(byte[])
+ */
public byte[] doFinal(byte[] M) {
byte[] r = mac.doFinal(M);
return r;
@@ -93,18 +92,19 @@ public class MacBasedPRF implements PRF {
/**
* Method getHLen.
-
-
- * @return int * @see fr.xephi.authme.security.pbkdf2.PRF#getHLen() */
+ *
+ * @return int * @see fr.xephi.authme.security.pbkdf2.PRF#getHLen()
+ */
public int getHLen() {
return hLen;
}
/**
* Method init.
+ *
* @param P byte[]
-
- * @see fr.xephi.authme.security.pbkdf2.PRF#init(byte[]) */
+ * @see fr.xephi.authme.security.pbkdf2.PRF#init(byte[])
+ */
public void init(byte[] P) {
try {
mac.init(new SecretKeySpec(P, macAlgorithm));
diff --git a/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2.java b/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2.java
index 7a623e066..f5bd34450 100644
--- a/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2.java
+++ b/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2.java
@@ -27,7 +27,7 @@ package fr.xephi.authme.security.pbkdf2;
* href="http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html"
* >http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
*
- *
+ *
* @author Matthias Gärtner
* @version 1.0
*/
@@ -36,64 +36,59 @@ public interface PBKDF2 {
/**
* Convert String-based input to internal byte array, then invoke PBKDF2.
* Desired key length defaults to Pseudo Random Function block size.
- *
- * @param inputPassword
- * Candidate password to compute the derived key for.
-
- * @return internal byte array */
+ *
+ * @param inputPassword Candidate password to compute the derived key for.
+ * @return internal byte array
+ */
public abstract byte[] deriveKey(String inputPassword);
/**
* Convert String-based input to internal byte array, then invoke PBKDF2.
- *
- * @param inputPassword
- * Candidate password to compute the derived key for.
- * @param dkLen
- * Specify desired key length
-
- * @return internal byte array */
+ *
+ * @param inputPassword Candidate password to compute the derived key for.
+ * @param dkLen Specify desired key length
+ * @return internal byte array
+ */
public abstract byte[] deriveKey(String inputPassword, int dkLen);
/**
* Convert String-based input to internal byte arrays, then invoke PBKDF2
* and verify result against the reference data that is supplied in the
* PBKDF2Parameters.
- *
- * @param inputPassword
- * Candidate password to compute the derived key for.
-
+ *
+ * @param inputPassword Candidate password to compute the derived key for.
* @return true
password match; false
incorrect
- * password */
+ * password
+ */
public abstract boolean verifyKey(String inputPassword);
/**
* Allow reading of configured parameters.
- *
-
- * @return Currently set parameters. */
+ *
+ * @return Currently set parameters.
+ */
public abstract PBKDF2Parameters getParameters();
/**
* Allow setting of configured parameters.
- *
+ *
* @param parameters
*/
public abstract void setParameters(PBKDF2Parameters parameters);
/**
* Get currently set Pseudo Random Function.
- *
-
- * @return Currently set Pseudo Random Function */
+ *
+ * @return Currently set Pseudo Random Function
+ */
public abstract PRF getPseudoRandomFunction();
/**
* Set the Pseudo Random Function to use. Note that deriveKeys/getPRF does
* init this object using the supplied candidate password. If this is
* undesired, one has to override getPRF.
- *
- * @param prf
- * Pseudo Random Function to set.
+ *
+ * @param prf Pseudo Random Function to set.
*/
public abstract void setPseudoRandomFunction(PRF prf);
}
diff --git a/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2Engine.java b/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2Engine.java
index 3e124da1b..fb8252ba2 100644
--- a/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2Engine.java
+++ b/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2Engine.java
@@ -10,17 +10,17 @@ import java.security.SecureRandom;
* Request for Comments: 2898 PKCS #5: Password-Based Cryptography Specification
*
* Version 2.0
- *
+ *
*
* PBKDF2 (P, S, c, dkLen)
- *
+ *
*
* Options:
*
* - PRF underlying pseudorandom function (hLen denotes the length in octets
* of the pseudorandom function output). PRF is pluggable.
*
- *
+ *
*
* Input:
*
@@ -30,13 +30,13 @@ import java.security.SecureRandom;
* - dkLen intended length in octets of the derived key, a positive integer,
* at most (2^32 - 1) * hLen
*
- *
+ *
*
* Output:
*
* - DK derived key, a dkLen-octet string
*
- *
+ *
*
*
* A free Java implementation of Password Based Key Derivation Function 2 as
@@ -64,10 +64,10 @@ import java.security.SecureRandom;
* http://www.
* gnu.org/licenses/old-licenses/lgpl-2.1.html.
*
- *
- * @see RFC 2898
+ *
* @author Matthias Gärtner
* @version 1.0
+ * @see RFC 2898
*/
public class PBKDF2Engine implements PBKDF2 {
@@ -88,9 +88,8 @@ public class PBKDF2Engine implements PBKDF2 {
* Constructor for PBKDF2 implementation object. PBKDF2 parameters are
* passed so that this implementation knows iteration count, method to use
* and String encoding.
- *
- * @param parameters
- * Data holder for iteration count, method to use et cetera.
+ *
+ * @param parameters Data holder for iteration count, method to use et cetera.
*/
public PBKDF2Engine(PBKDF2Parameters parameters) {
this.parameters = parameters;
@@ -101,262 +100,26 @@ public class PBKDF2Engine implements PBKDF2 {
* Constructor for PBKDF2 implementation object. PBKDF2 parameters are
* passed so that this implementation knows iteration count, method to use
* and String encoding.
- *
- * @param parameters
- * Data holder for iteration count, method to use et cetera.
- * @param prf
- * Supply customer Pseudo Random Function.
+ *
+ * @param parameters Data holder for iteration count, method to use et cetera.
+ * @param prf Supply customer Pseudo Random Function.
*/
public PBKDF2Engine(PBKDF2Parameters parameters, PRF prf) {
this.parameters = parameters;
this.prf = prf;
}
- /**
- * Method deriveKey.
- * @param inputPassword String
-
-
- * @return byte[] * @see fr.xephi.authme.security.pbkdf2.PBKDF2#deriveKey(String) */
- public byte[] deriveKey(String inputPassword) {
- return deriveKey(inputPassword, 0);
- }
-
- /**
- * Method deriveKey.
- * @param inputPassword String
- * @param dkLen int
-
-
- * @return byte[] * @see fr.xephi.authme.security.pbkdf2.PBKDF2#deriveKey(String, int) */
- public byte[] deriveKey(String inputPassword, int dkLen) {
- byte[] r = null;
- byte P[] = null;
- String charset = parameters.getHashCharset();
- if (inputPassword == null) {
- inputPassword = "";
- }
- try {
- if (charset == null) {
- P = inputPassword.getBytes();
- } else {
- P = inputPassword.getBytes(charset);
- }
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException(e);
- }
- assertPRF(P);
- if (dkLen == 0) {
- dkLen = prf.getHLen();
- }
- r = PBKDF2(prf, parameters.getSalt(), parameters.getIterationCount(), dkLen);
- return r;
- }
-
- /**
- * Method verifyKey.
- * @param inputPassword String
-
-
- * @return boolean * @see fr.xephi.authme.security.pbkdf2.PBKDF2#verifyKey(String) */
- public boolean verifyKey(String inputPassword) {
- byte[] referenceKey = getParameters().getDerivedKey();
- if (referenceKey == null || referenceKey.length == 0) {
- return false;
- }
- byte[] inputKey = deriveKey(inputPassword, referenceKey.length);
-
- if (inputKey == null || inputKey.length != referenceKey.length) {
- return false;
- }
- for (int i = 0; i < inputKey.length; i++) {
- if (inputKey[i] != referenceKey[i]) {
- return false;
- }
- }
- return true;
- }
-
- /**
- * Factory method. Default implementation is (H)MAC-based. To be overridden
- * in derived classes.
- *
- * @param P
- * User-supplied candidate password as array of bytes.
- */
- protected void assertPRF(byte[] P) {
- if (prf == null) {
- prf = new MacBasedPRF(parameters.getHashAlgorithm());
- }
- prf.init(P);
- }
-
- /**
- * Method getPseudoRandomFunction.
-
-
- * @return PRF * @see fr.xephi.authme.security.pbkdf2.PBKDF2#getPseudoRandomFunction() */
- public PRF getPseudoRandomFunction() {
- return prf;
- }
-
- /**
- * Core Password Based Key Derivation Function 2.
- *
-
- * @param prf
- * Pseudo Random Function (i.e. HmacSHA1)
- * @param S
- * Salt as array of bytes. null
means no salt.
- * @param c
- * Iteration count (see RFC 2898 4.2)
- * @param dkLen
- * desired length of derived key.
-
- * @return internal byte array * @see RFC 2898 5.2 */
- protected byte[] PBKDF2(PRF prf, byte[] S, int c, int dkLen) {
- if (S == null) {
- S = new byte[0];
- }
- int hLen = prf.getHLen();
- int l = ceil(dkLen, hLen);
- int r = dkLen - (l - 1) * hLen;
- byte T[] = new byte[l * hLen];
- int ti_offset = 0;
- for (int i = 1; i <= l; i++) {
- _F(T, ti_offset, prf, S, c, i);
- ti_offset += hLen;
- }
- if (r < hLen) {
- // Incomplete last block
- byte DK[] = new byte[dkLen];
- System.arraycopy(T, 0, DK, 0, dkLen);
- return DK;
- }
- return T;
- }
-
- /**
- * Integer division with ceiling function.
- *
-
- * @param a
- * @param b
-
- * @return ceil(a/b) * @see RFC 2898 5.2 Step
- * 2. */
- protected int ceil(int a, int b) {
- int m = 0;
- if (a % b > 0) {
- m = 1;
- }
- return a / b + m;
- }
-
- /**
- * Function F.
- *
-
- * @param dest
- * Destination byte buffer
- * @param offset
- * Offset into destination byte buffer
- * @param prf
- * Pseudo Random Function
- * @param S
- * Salt as array of bytes
- * @param c
- * Iteration count
- * @param blockIndex
- * @see RFC 2898 5.2 Step
- * 3. */
- protected void _F(byte[] dest, int offset, PRF prf, byte[] S, int c,
- int blockIndex) {
- int hLen = prf.getHLen();
- byte U_r[] = new byte[hLen];
-
- // U0 = S || INT (i);
- byte U_i[] = new byte[S.length + 4];
- System.arraycopy(S, 0, U_i, 0, S.length);
- INT(U_i, S.length, blockIndex);
-
- for (int i = 0; i < c; i++) {
- U_i = prf.doFinal(U_i);
- xor(U_r, U_i);
- }
- System.arraycopy(U_r, 0, dest, offset, hLen);
- }
-
- /**
- * Block-Xor. Xor source bytes into destination byte buffer. Destination
- * buffer must be same length or less than source buffer.
- *
- * @param dest
- * @param src
- */
- protected void xor(byte[] dest, byte[] src) {
- for (int i = 0; i < dest.length; i++) {
- dest[i] ^= src[i];
- }
- }
-
- /**
- * Four-octet encoding of the integer i, most significant octet first.
- *
-
- * @param dest
- * @param offset
- * @param i
- * @see RFC 2898 5.2 Step
- * 3. */
- protected void INT(byte[] dest, int offset, int i) {
- dest[offset + 0] = (byte) (i / (256 * 256 * 256));
- dest[offset + 1] = (byte) (i / (256 * 256));
- dest[offset + 2] = (byte) (i / (256));
- dest[offset + 3] = (byte) (i);
- }
-
- /**
- * Method getParameters.
-
-
- * @return PBKDF2Parameters * @see fr.xephi.authme.security.pbkdf2.PBKDF2#getParameters() */
- public PBKDF2Parameters getParameters() {
- return parameters;
- }
-
- /**
- * Method setParameters.
- * @param parameters PBKDF2Parameters
-
- * @see fr.xephi.authme.security.pbkdf2.PBKDF2#setParameters(PBKDF2Parameters) */
- public void setParameters(PBKDF2Parameters parameters) {
- this.parameters = parameters;
- }
-
- /**
- * Method setPseudoRandomFunction.
- * @param prf PRF
-
- * @see fr.xephi.authme.security.pbkdf2.PBKDF2#setPseudoRandomFunction(PRF) */
- public void setPseudoRandomFunction(PRF prf) {
- this.prf = prf;
- }
-
/**
* Convenience client function. Convert supplied password with random 8-byte
* salt and 1000 iterations using HMacSHA1. Assume that password is in
* ISO-8559-1 encoding. Output result as
* "Salt:iteration-count:PBKDF2" with binary data in hexadecimal
* encoding.
- *
+ *
* Example: Password "password" (without the quotes) leads to
* 48290A0B96C426C3:1000:973899B1D4AFEB3ED371060D0797E0EE0142BD04
- *
- * @param args
- * Supply the password as argument.
-
-
+ *
+ * @param args Supply the password as argument.
* @throws IOException * @throws NoSuchAlgorithmException * @throws NoSuchAlgorithmException
*/
public static void main(String[] args)
@@ -394,4 +157,225 @@ public class PBKDF2Engine implements PBKDF2 {
System.exit(verifyOK ? 0 : 1);
}
}
+
+ /**
+ * Method deriveKey.
+ *
+ * @param inputPassword String
+ * @return byte[] * @see fr.xephi.authme.security.pbkdf2.PBKDF2#deriveKey(String)
+ */
+ public byte[] deriveKey(String inputPassword) {
+ return deriveKey(inputPassword, 0);
+ }
+
+ /**
+ * Method deriveKey.
+ *
+ * @param inputPassword String
+ * @param dkLen int
+ * @return byte[] * @see fr.xephi.authme.security.pbkdf2.PBKDF2#deriveKey(String, int)
+ */
+ public byte[] deriveKey(String inputPassword, int dkLen) {
+ byte[] r = null;
+ byte P[] = null;
+ String charset = parameters.getHashCharset();
+ if (inputPassword == null) {
+ inputPassword = "";
+ }
+ try {
+ if (charset == null) {
+ P = inputPassword.getBytes();
+ } else {
+ P = inputPassword.getBytes(charset);
+ }
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException(e);
+ }
+ assertPRF(P);
+ if (dkLen == 0) {
+ dkLen = prf.getHLen();
+ }
+ r = PBKDF2(prf, parameters.getSalt(), parameters.getIterationCount(), dkLen);
+ return r;
+ }
+
+ /**
+ * Method verifyKey.
+ *
+ * @param inputPassword String
+ * @return boolean * @see fr.xephi.authme.security.pbkdf2.PBKDF2#verifyKey(String)
+ */
+ public boolean verifyKey(String inputPassword) {
+ byte[] referenceKey = getParameters().getDerivedKey();
+ if (referenceKey == null || referenceKey.length == 0) {
+ return false;
+ }
+ byte[] inputKey = deriveKey(inputPassword, referenceKey.length);
+
+ if (inputKey == null || inputKey.length != referenceKey.length) {
+ return false;
+ }
+ for (int i = 0; i < inputKey.length; i++) {
+ if (inputKey[i] != referenceKey[i]) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Factory method. Default implementation is (H)MAC-based. To be overridden
+ * in derived classes.
+ *
+ * @param P User-supplied candidate password as array of bytes.
+ */
+ protected void assertPRF(byte[] P) {
+ if (prf == null) {
+ prf = new MacBasedPRF(parameters.getHashAlgorithm());
+ }
+ prf.init(P);
+ }
+
+ /**
+ * Method getPseudoRandomFunction.
+ *
+ * @return PRF * @see fr.xephi.authme.security.pbkdf2.PBKDF2#getPseudoRandomFunction()
+ */
+ public PRF getPseudoRandomFunction() {
+ return prf;
+ }
+
+ /**
+ * Method setPseudoRandomFunction.
+ *
+ * @param prf PRF
+ * @see fr.xephi.authme.security.pbkdf2.PBKDF2#setPseudoRandomFunction(PRF)
+ */
+ public void setPseudoRandomFunction(PRF prf) {
+ this.prf = prf;
+ }
+
+ /**
+ * Core Password Based Key Derivation Function 2.
+ *
+ * @param prf Pseudo Random Function (i.e. HmacSHA1)
+ * @param S Salt as array of bytes. null
means no salt.
+ * @param c Iteration count (see RFC 2898 4.2)
+ * @param dkLen desired length of derived key.
+ * @return internal byte array * @see RFC 2898 5.2
+ */
+ protected byte[] PBKDF2(PRF prf, byte[] S, int c, int dkLen) {
+ if (S == null) {
+ S = new byte[0];
+ }
+ int hLen = prf.getHLen();
+ int l = ceil(dkLen, hLen);
+ int r = dkLen - (l - 1) * hLen;
+ byte T[] = new byte[l * hLen];
+ int ti_offset = 0;
+ for (int i = 1; i <= l; i++) {
+ _F(T, ti_offset, prf, S, c, i);
+ ti_offset += hLen;
+ }
+ if (r < hLen) {
+ // Incomplete last block
+ byte DK[] = new byte[dkLen];
+ System.arraycopy(T, 0, DK, 0, dkLen);
+ return DK;
+ }
+ return T;
+ }
+
+ /**
+ * Integer division with ceiling function.
+ *
+ * @param a
+ * @param b
+ * @return ceil(a/b) * @see RFC 2898 5.2 Step
+ * 2.
+ */
+ protected int ceil(int a, int b) {
+ int m = 0;
+ if (a % b > 0) {
+ m = 1;
+ }
+ return a / b + m;
+ }
+
+ /**
+ * Function F.
+ *
+ * @param dest Destination byte buffer
+ * @param offset Offset into destination byte buffer
+ * @param prf Pseudo Random Function
+ * @param S Salt as array of bytes
+ * @param c Iteration count
+ * @param blockIndex
+ * @see RFC 2898 5.2 Step
+ * 3.
+ */
+ protected void _F(byte[] dest, int offset, PRF prf, byte[] S, int c,
+ int blockIndex) {
+ int hLen = prf.getHLen();
+ byte U_r[] = new byte[hLen];
+
+ // U0 = S || INT (i);
+ byte U_i[] = new byte[S.length + 4];
+ System.arraycopy(S, 0, U_i, 0, S.length);
+ INT(U_i, S.length, blockIndex);
+
+ for (int i = 0; i < c; i++) {
+ U_i = prf.doFinal(U_i);
+ xor(U_r, U_i);
+ }
+ System.arraycopy(U_r, 0, dest, offset, hLen);
+ }
+
+ /**
+ * Block-Xor. Xor source bytes into destination byte buffer. Destination
+ * buffer must be same length or less than source buffer.
+ *
+ * @param dest
+ * @param src
+ */
+ protected void xor(byte[] dest, byte[] src) {
+ for (int i = 0; i < dest.length; i++) {
+ dest[i] ^= src[i];
+ }
+ }
+
+ /**
+ * Four-octet encoding of the integer i, most significant octet first.
+ *
+ * @param dest
+ * @param offset
+ * @param i
+ * @see RFC 2898 5.2 Step
+ * 3.
+ */
+ protected void INT(byte[] dest, int offset, int i) {
+ dest[offset + 0] = (byte) (i / (256 * 256 * 256));
+ dest[offset + 1] = (byte) (i / (256 * 256));
+ dest[offset + 2] = (byte) (i / (256));
+ dest[offset + 3] = (byte) (i);
+ }
+
+ /**
+ * Method getParameters.
+ *
+ * @return PBKDF2Parameters * @see fr.xephi.authme.security.pbkdf2.PBKDF2#getParameters()
+ */
+ public PBKDF2Parameters getParameters() {
+ return parameters;
+ }
+
+ /**
+ * Method setParameters.
+ *
+ * @param parameters PBKDF2Parameters
+ * @see fr.xephi.authme.security.pbkdf2.PBKDF2#setParameters(PBKDF2Parameters)
+ */
+ public void setParameters(PBKDF2Parameters parameters) {
+ this.parameters = parameters;
+ }
}
diff --git a/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2Formatter.java b/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2Formatter.java
index 68f3fa6c9..52e1c85c9 100644
--- a/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2Formatter.java
+++ b/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2Formatter.java
@@ -27,7 +27,7 @@ package fr.xephi.authme.security.pbkdf2;
* href="http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html"
* >http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
*
- *
+ *
* @author Matthias Gärtner
* @version 1.0
*/
@@ -35,22 +35,20 @@ public interface PBKDF2Formatter {
/**
* Convert parameters to String.
- *
- * @param p
- * Parameters object to output.
-
- * @return String representation */
+ *
+ * @param p Parameters object to output.
+ * @return String representation
+ */
public abstract String toString(PBKDF2Parameters p);
/**
* Convert String to parameters. Depending on actual implementation, it may
* be required to set further fields externally.
- *
- * @param s
- * String representation of parameters to decode.
-
+ *
+ * @param s String representation of parameters to decode.
* @param p PBKDF2Parameters
* @return false
syntax OK, true
some syntax
- * issue. */
+ * issue.
+ */
public abstract boolean fromString(PBKDF2Parameters p, String s);
}
diff --git a/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2HexFormatter.java b/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2HexFormatter.java
index 8ae057fd7..32f393bd8 100644
--- a/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2HexFormatter.java
+++ b/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2HexFormatter.java
@@ -27,7 +27,7 @@ package fr.xephi.authme.security.pbkdf2;
* href="http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html"
* >http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
*
- *
+ *
* @author Matthias Gärtner
* @version 1.0
*/
@@ -35,11 +35,11 @@ public class PBKDF2HexFormatter implements PBKDF2Formatter {
/**
* Method fromString.
+ *
* @param p PBKDF2Parameters
* @param s String
-
-
- * @return boolean * @see fr.xephi.authme.security.pbkdf2.PBKDF2Formatter#fromString(PBKDF2Parameters, String) */
+ * @return boolean * @see fr.xephi.authme.security.pbkdf2.PBKDF2Formatter#fromString(PBKDF2Parameters, String)
+ */
public boolean fromString(PBKDF2Parameters p, String s) {
if (p == null || s == null) {
return true;
@@ -62,10 +62,10 @@ public class PBKDF2HexFormatter implements PBKDF2Formatter {
/**
* Method toString.
+ *
* @param p PBKDF2Parameters
-
-
- * @return String * @see fr.xephi.authme.security.pbkdf2.PBKDF2Formatter#toString(PBKDF2Parameters) */
+ * @return String * @see fr.xephi.authme.security.pbkdf2.PBKDF2Formatter#toString(PBKDF2Parameters)
+ */
public String toString(PBKDF2Parameters p) {
String s = BinTools.bin2hex(p.getSalt()) + ":" + String.valueOf(p.getIterationCount()) + ":" + BinTools.bin2hex(p.getDerivedKey());
return s;
diff --git a/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2Parameters.java b/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2Parameters.java
index 5dde7a998..d962648b2 100644
--- a/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2Parameters.java
+++ b/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2Parameters.java
@@ -4,7 +4,7 @@ package fr.xephi.authme.security.pbkdf2;
*
* Parameter data holder for PBKDF2 configuration.
*
- *
+ *
*
*
* A free Java implementation of Password Based Key Derivation Function 2 as
@@ -32,7 +32,7 @@ package fr.xephi.authme.security.pbkdf2;
* href="http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html"
* >http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
*
- *
+ *
* @author Matthias Gärtner
* @version 1.0
*/
@@ -55,7 +55,6 @@ public class PBKDF2Parameters {
/**
* Constructor. Defaults to null
for byte arrays, UTF-8 as
* character set and 1000 for iteration count.
- *
*/
public PBKDF2Parameters() {
this.hashAlgorithm = null;
@@ -67,18 +66,14 @@ public class PBKDF2Parameters {
/**
* Constructor.
- *
- * @param hashAlgorithm
- * for example HMacSHA1 or HMacMD5
- * @param hashCharset
- * for example UTF-8
- * @param salt
- * Salt as byte array, may be null
(not recommended)
- * @param iterationCount
- * Number of iterations to execute. Recommended value 1000.
+ *
+ * @param hashAlgorithm for example HMacSHA1 or HMacMD5
+ * @param hashCharset for example UTF-8
+ * @param salt Salt as byte array, may be null
(not recommended)
+ * @param iterationCount Number of iterations to execute. Recommended value 1000.
*/
public PBKDF2Parameters(String hashAlgorithm, String hashCharset,
- byte[] salt, int iterationCount) {
+ byte[] salt, int iterationCount) {
this.hashAlgorithm = hashAlgorithm;
this.hashCharset = hashCharset;
this.salt = salt;
@@ -88,20 +83,15 @@ public class PBKDF2Parameters {
/**
* Constructor.
- *
- * @param hashAlgorithm
- * for example HMacSHA1 or HMacMD5
- * @param hashCharset
- * for example UTF-8
- * @param salt
- * Salt as byte array, may be null
(not recommended)
- * @param iterationCount
- * Number of iterations to execute. Recommended value 1000.
- * @param derivedKey
- * Convenience data holder, not used during computation.
+ *
+ * @param hashAlgorithm for example HMacSHA1 or HMacMD5
+ * @param hashCharset for example UTF-8
+ * @param salt Salt as byte array, may be null
(not recommended)
+ * @param iterationCount Number of iterations to execute. Recommended value 1000.
+ * @param derivedKey Convenience data holder, not used during computation.
*/
public PBKDF2Parameters(String hashAlgorithm, String hashCharset,
- byte[] salt, int iterationCount, byte[] derivedKey) {
+ byte[] salt, int iterationCount, byte[] derivedKey) {
this.hashAlgorithm = hashAlgorithm;
this.hashCharset = hashCharset;
this.salt = salt;
@@ -111,14 +101,16 @@ public class PBKDF2Parameters {
/**
* Method getIterationCount.
-
- * @return int */
+ *
+ * @return int
+ */
public int getIterationCount() {
return iterationCount;
}
/**
* Method setIterationCount.
+ *
* @param iterationCount int
*/
public void setIterationCount(int iterationCount) {
@@ -127,14 +119,16 @@ public class PBKDF2Parameters {
/**
* Method getSalt.
-
- * @return byte[] */
+ *
+ * @return byte[]
+ */
public byte[] getSalt() {
return salt;
}
/**
* Method setSalt.
+ *
* @param salt byte[]
*/
public void setSalt(byte[] salt) {
@@ -143,14 +137,16 @@ public class PBKDF2Parameters {
/**
* Method getDerivedKey.
-
- * @return byte[] */
+ *
+ * @return byte[]
+ */
public byte[] getDerivedKey() {
return derivedKey;
}
/**
* Method setDerivedKey.
+ *
* @param derivedKey byte[]
*/
public void setDerivedKey(byte[] derivedKey) {
@@ -159,14 +155,16 @@ public class PBKDF2Parameters {
/**
* Method getHashAlgorithm.
-
- * @return String */
+ *
+ * @return String
+ */
public String getHashAlgorithm() {
return hashAlgorithm;
}
/**
* Method setHashAlgorithm.
+ *
* @param hashAlgorithm String
*/
public void setHashAlgorithm(String hashAlgorithm) {
@@ -175,14 +173,16 @@ public class PBKDF2Parameters {
/**
* Method getHashCharset.
-
- * @return String */
+ *
+ * @return String
+ */
public String getHashCharset() {
return hashCharset;
}
/**
* Method setHashCharset.
+ *
* @param hashCharset String
*/
public void setHashCharset(String hashCharset) {
diff --git a/src/main/java/fr/xephi/authme/security/pbkdf2/PRF.java b/src/main/java/fr/xephi/authme/security/pbkdf2/PRF.java
index c7dbf547f..42c64600d 100644
--- a/src/main/java/fr/xephi/authme/security/pbkdf2/PRF.java
+++ b/src/main/java/fr/xephi/authme/security/pbkdf2/PRF.java
@@ -27,7 +27,7 @@ package fr.xephi.authme.security.pbkdf2;
* href="http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html"
* >http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
*
- *
+ *
* @author Matthias Gärtner
* @version 1.0
*/
@@ -35,27 +35,25 @@ public interface PRF {
/**
* Initialize this instance with the user-supplied password.
- *
- * @param P
- * The password supplied as array of bytes. It is the caller's
- * task to convert String passwords to bytes as appropriate.
+ *
+ * @param P The password supplied as array of bytes. It is the caller's
+ * task to convert String passwords to bytes as appropriate.
*/
public void init(byte[] P);
/**
* Pseudo Random Function
- *
- * @param M
- * Input data/message etc. Together with any data supplied during
- * initilization.
-
- * @return Random bytes of hLen length. */
+ *
+ * @param M Input data/message etc. Together with any data supplied during
+ * initilization.
+ * @return Random bytes of hLen length.
+ */
public byte[] doFinal(byte[] M);
/**
* Query block size of underlying algorithm/mechanism.
- *
-
- * @return block size */
+ *
+ * @return block size
+ */
public int getHLen();
}
diff --git a/src/main/java/fr/xephi/authme/settings/CustomConfiguration.java b/src/main/java/fr/xephi/authme/settings/CustomConfiguration.java
index 15e651aa5..757bfe332 100644
--- a/src/main/java/fr/xephi/authme/settings/CustomConfiguration.java
+++ b/src/main/java/fr/xephi/authme/settings/CustomConfiguration.java
@@ -1,5 +1,10 @@
package fr.xephi.authme.settings;
+import fr.xephi.authme.AuthMe;
+import fr.xephi.authme.ConsoleLogger;
+import org.bukkit.configuration.InvalidConfigurationException;
+import org.bukkit.configuration.file.YamlConfiguration;
+
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -7,12 +12,6 @@ import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
-import org.bukkit.configuration.InvalidConfigurationException;
-import org.bukkit.configuration.file.YamlConfiguration;
-
-import fr.xephi.authme.AuthMe;
-import fr.xephi.authme.ConsoleLogger;
-
/**
*/
public abstract class CustomConfiguration extends YamlConfiguration {
@@ -21,6 +20,7 @@ public abstract class CustomConfiguration extends YamlConfiguration {
/**
* Constructor for CustomConfiguration.
+ *
* @param file the config file
*/
public CustomConfiguration(File file) {
diff --git a/src/main/java/fr/xephi/authme/settings/Messages.java b/src/main/java/fr/xephi/authme/settings/Messages.java
index 15b10c4d5..32a5192bc 100644
--- a/src/main/java/fr/xephi/authme/settings/Messages.java
+++ b/src/main/java/fr/xephi/authme/settings/Messages.java
@@ -1,10 +1,9 @@
package fr.xephi.authme.settings;
-import java.io.File;
-
+import fr.xephi.authme.ConsoleLogger;
import org.bukkit.command.CommandSender;
-import fr.xephi.authme.ConsoleLogger;
+import java.io.File;
/**
*/
@@ -15,6 +14,7 @@ public class Messages extends CustomConfiguration {
/**
* Constructor for Messages.
+ *
* @param file the configuration file
* @param lang the code of the language to use
*/
@@ -25,6 +25,13 @@ public class Messages extends CustomConfiguration {
this.lang = lang;
}
+ public static Messages getInstance() {
+ if (singleton == null) {
+ singleton = new Messages(Settings.messageFile, Settings.messagesLanguage);
+ }
+ return singleton;
+ }
+
public void send(CommandSender sender, String msg) {
if (!Settings.messagesLanguage.equalsIgnoreCase(singleton.lang)) {
singleton.reloadMessages();
@@ -62,13 +69,6 @@ public class Messages extends CustomConfiguration {
return loc;
}
- public static Messages getInstance() {
- if (singleton == null) {
- singleton = new Messages(Settings.messageFile, Settings.messagesLanguage);
- }
- return singleton;
- }
-
public void reloadMessages() {
singleton = new Messages(Settings.messageFile, Settings.messagesLanguage);
}
diff --git a/src/main/java/fr/xephi/authme/settings/OtherAccounts.java b/src/main/java/fr/xephi/authme/settings/OtherAccounts.java
index dcaf3c00e..9dee23d14 100644
--- a/src/main/java/fr/xephi/authme/settings/OtherAccounts.java
+++ b/src/main/java/fr/xephi/authme/settings/OtherAccounts.java
@@ -1,15 +1,14 @@
package fr.xephi.authme.settings;
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
-import org.bukkit.Bukkit;
-import org.bukkit.entity.Player;
-
/**
- *
* @author Xephi59
* @version $Revision: 1.0 $
*/
@@ -24,19 +23,11 @@ public class OtherAccounts extends CustomConfiguration {
save();
}
- /**
- * Method clear.
- * @param uuid UUID
- */
- public void clear(UUID uuid) {
- set(uuid.toString(), new ArrayList());
- save();
- }
-
/**
* Method getInstance.
-
- * @return OtherAccounts */
+ *
+ * @return OtherAccounts
+ */
public static OtherAccounts getInstance() {
if (others == null) {
others = new OtherAccounts();
@@ -44,8 +35,19 @@ public class OtherAccounts extends CustomConfiguration {
return others;
}
+ /**
+ * Method clear.
+ *
+ * @param uuid UUID
+ */
+ public void clear(UUID uuid) {
+ set(uuid.toString(), new ArrayList());
+ save();
+ }
+
/**
* Method addPlayer.
+ *
* @param uuid UUID
*/
public void addPlayer(UUID uuid) {
@@ -64,6 +66,7 @@ public class OtherAccounts extends CustomConfiguration {
/**
* Method removePlayer.
+ *
* @param uuid UUID
*/
public void removePlayer(UUID uuid) {
@@ -82,9 +85,10 @@ public class OtherAccounts extends CustomConfiguration {
/**
* Method getAllPlayersByUUID.
+ *
* @param uuid UUID
-
- * @return List */
+ * @return List
+ */
public List getAllPlayersByUUID(UUID uuid) {
return this.getStringList(uuid.toString());
}
diff --git a/src/main/java/fr/xephi/authme/settings/Settings.java b/src/main/java/fr/xephi/authme/settings/Settings.java
index 94f032d81..49a78db01 100644
--- a/src/main/java/fr/xephi/authme/settings/Settings.java
+++ b/src/main/java/fr/xephi/authme/settings/Settings.java
@@ -1,40 +1,29 @@
package fr.xephi.authme.settings;
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.bukkit.configuration.file.YamlConfiguration;
-
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.datasource.DataSource.DataSourceType;
import fr.xephi.authme.security.HashAlgorithm;
+import org.bukkit.configuration.file.YamlConfiguration;
+
+import java.io.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
/**
*/
public final class Settings extends YamlConfiguration {
- private static AuthMe plugin;
- private static Settings instance;
-
- // This is not an option!
- public static boolean antiBotInAction = false;
-
public static final File PLUGIN_FOLDER = AuthMe.getInstance().getDataFolder();
public static final File MODULE_FOLDER = new File(PLUGIN_FOLDER, "modules");
public static final File CACHE_FOLDER = new File(PLUGIN_FOLDER, "cache");
public static final File AUTH_FILE = new File(PLUGIN_FOLDER, "auths.db");
public static final File SETTINGS_FILE = new File(PLUGIN_FOLDER, "config.yml");
public static final File LOG_FILE = new File(PLUGIN_FOLDER, "authme.log");
-
+ // This is not an option!
+ public static boolean antiBotInAction = false;
public static File messageFile;
public static List allowCommands;
public static List getJoinPermissions;
@@ -56,10 +45,8 @@ public final class Settings extends YamlConfiguration {
public static HashAlgorithm getPasswordHash;
public static boolean useLogging = false;
public static int purgeDelay = 60;
-
// Due to compatibility issues with plugins like FactionsChat
public static Boolean isChatAllowed;
-
public static boolean isPermissionCheckEnabled, isRegistrationEnabled,
isForcedRegistrationEnabled, isTeleportToSpawnEnabled,
isSessionsEnabled, isAllowRestrictedIp,
@@ -80,7 +67,6 @@ public final class Settings extends YamlConfiguration {
broadcastWelcomeMessage, forceRegKick, forceRegLogin,
checkVeryGames, delayJoinLeaveMessages, noTeleport, applyBlindEffect,
customAttributes, generateImage, isRemoveSpeedEnabled, isMySQLWebsite;
-
public static String getNickRegex, getUnloggedinGroup, getMySQLHost,
getMySQLPort, getMySQLUsername, getMySQLPassword, getMySQLDatabase,
getMySQLTablename, getMySQLColumnName, getMySQLColumnPassword,
@@ -94,7 +80,6 @@ public final class Settings extends YamlConfiguration {
getPhpbbPrefix, getWordPressPrefix, getMySQLColumnLogged,
spawnPriority, crazyloginFileName, getPassRegex,
getMySQLColumnRealName;
-
public static int getWarnMessageInterval, getSessionTimeout,
getRegistrationTimeout, getMaxNickLength, getMinNickLength,
getPasswordMinLen, getMovementRadius, getmaxRegPerIp,
@@ -103,11 +88,13 @@ public final class Settings extends YamlConfiguration {
getmaxRegPerEmail, bCryptLog2Rounds, getPhpbbGroup,
antiBotSensibility, antiBotDuration, delayRecall, getMaxLoginPerIp,
getMaxJoinPerIp, getMySQLMaxConnections;
-
protected static YamlConfiguration configFile;
+ private static AuthMe plugin;
+ private static Settings instance;
/**
* Constructor for Settings.
+ *
* @param pl AuthMe
*/
public Settings(AuthMe pl) {
@@ -118,8 +105,9 @@ public final class Settings extends YamlConfiguration {
/**
* Method reload.
-
- * @throws Exception */
+ *
+ * @throws Exception
+ */
public static void reload() throws Exception {
plugin.getLogger().info("Loading Configuration File...");
boolean exist = SETTINGS_FILE.exists();
@@ -302,6 +290,189 @@ public final class Settings extends YamlConfiguration {
}
+ /**
+ * Method setValue.
+ *
+ * @param key String
+ * @param value Object
+ */
+ public static void setValue(String key, Object value) {
+ instance.set(key, value);
+ save();
+ }
+
+ /**
+ * Method getPasswordHash.
+ *
+ * @return HashAlgorithm
+ */
+ private static HashAlgorithm getPasswordHash() {
+ String key = "settings.security.passwordHash";
+ try {
+ return HashAlgorithm.valueOf(configFile.getString(key, "SHA256").toUpperCase());
+ } catch (IllegalArgumentException ex) {
+ ConsoleLogger.showError("Unknown Hash Algorithm; defaulting to SHA256");
+ return HashAlgorithm.SHA256;
+ }
+ }
+
+ /**
+ * Method getDataSource.
+ *
+ * @return DataSourceType
+ */
+ private static DataSourceType getDataSource() {
+ String key = "DataSource.backend";
+ try {
+ return DataSource.DataSourceType.valueOf(configFile.getString(key, "sqlite").toUpperCase());
+ } catch (IllegalArgumentException ex) {
+ ConsoleLogger.showError("Unknown database backend; defaulting to SQLite database");
+ return DataSource.DataSourceType.SQLITE;
+ }
+ }
+
+ /**
+ * Config option for setting and check restricted user by username;ip ,
+ * return false if ip and name doesn't match with player that join the
+ * server, so player has a restricted access
+ *
+ * @param name String
+ * @param ip String
+ * @return boolean
+ */
+ public static boolean getRestrictedIp(String name, String ip) {
+
+ Iterator iterator = getRestrictedIp.iterator();
+ boolean trueOnce = false;
+ boolean nameFound = false;
+ while (iterator.hasNext()) {
+ String[] args = iterator.next().split(";");
+ String testName = args[0];
+ String testIp = args[1];
+ if (testName.equalsIgnoreCase(name)) {
+ nameFound = true;
+ if (testIp.equalsIgnoreCase(ip)) {
+ trueOnce = true;
+ }
+ }
+ }
+ return !nameFound || trueOnce;
+ }
+
+ /**
+ * Saves the configuration to disk
+ *
+ * @return True if saved successfully
+ */
+ public static boolean save() {
+ try {
+ instance.save(SETTINGS_FILE);
+ return true;
+ } catch (Exception ex) {
+ return false;
+ }
+ }
+
+ /**
+ * Method checkLang.
+ *
+ * @param lang String
+ * @return String
+ */
+ public static String checkLang(String lang) {
+ if (new File(PLUGIN_FOLDER, "messages" + File.separator + "messages_" + lang + ".yml").exists()) {
+ ConsoleLogger.info("Set Language to: " + lang);
+ return lang;
+ }
+ if (AuthMe.class.getResourceAsStream("/messages/messages_" + lang + ".yml") != null) {
+ ConsoleLogger.info("Set Language to: " + lang);
+ return lang;
+ }
+ ConsoleLogger.info("Language file not found for " + lang + ", set to default language: en !");
+ return "en";
+ }
+
+ /**
+ * Method switchAntiBotMod.
+ *
+ * @param mode boolean
+ */
+ public static void switchAntiBotMod(boolean mode) {
+ if (mode) {
+ isKickNonRegisteredEnabled = true;
+ antiBotInAction = true;
+ } else {
+ isKickNonRegisteredEnabled = configFile.getBoolean("settings.restrictions.kickNonRegistered", false);
+ antiBotInAction = false;
+ }
+ }
+
+ private static void getWelcomeMessage() {
+ AuthMe plugin = AuthMe.getInstance();
+ welcomeMsg = new ArrayList<>();
+ if (!useWelcomeMessage) {
+ return;
+ }
+ if (!(new File(plugin.getDataFolder() + File.separator + "welcome.txt").exists())) {
+ try {
+ FileWriter fw = new FileWriter(plugin.getDataFolder() + File.separator + "welcome.txt", true);
+ BufferedWriter w = new BufferedWriter(fw);
+ w.write("Welcome {PLAYER} on {SERVER} server");
+ w.newLine();
+ w.write("This server uses " + AuthMe.getPluginName() + " protection!");
+ w.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ try {
+ FileReader fr = new FileReader(plugin.getDataFolder() + File.separator + "welcome.txt");
+ BufferedReader br = new BufferedReader(fr);
+ String line;
+ while ((line = br.readLine()) != null) {
+ welcomeMsg.add(line);
+ }
+ br.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Method isEmailCorrect.
+ *
+ * @param email String
+ * @return boolean
+ */
+ public static boolean isEmailCorrect(String email) {
+ if (!email.contains("@"))
+ return false;
+ if (email.equalsIgnoreCase("your@email.com"))
+ return false;
+ String emailDomain = email.split("@")[1];
+ boolean correct = true;
+ if (emailWhitelist != null && !emailWhitelist.isEmpty()) {
+ for (String domain : emailWhitelist) {
+ if (!domain.equalsIgnoreCase(emailDomain)) {
+ correct = false;
+ } else {
+ correct = true;
+ break;
+ }
+ }
+ return correct;
+ }
+ if (emailBlacklist != null && !emailBlacklist.isEmpty()) {
+ for (String domain : emailBlacklist) {
+ if (domain.equalsIgnoreCase(emailDomain)) {
+ correct = false;
+ break;
+ }
+ }
+ }
+ return correct;
+ }
+
public void mergeConfig() {
boolean changes = false;
if (contains("Xenoforo.predefinedSalt")) {
@@ -512,92 +683,13 @@ public final class Settings extends YamlConfiguration {
}
}
- /**
- * Method setValue.
- * @param key String
- * @param value Object
- */
- public static void setValue(String key, Object value) {
- instance.set(key, value);
- save();
- }
-
- /**
- * Method getPasswordHash.
-
- * @return HashAlgorithm */
- private static HashAlgorithm getPasswordHash() {
- String key = "settings.security.passwordHash";
- try {
- return HashAlgorithm.valueOf(configFile.getString(key, "SHA256").toUpperCase());
- } catch (IllegalArgumentException ex) {
- ConsoleLogger.showError("Unknown Hash Algorithm; defaulting to SHA256");
- return HashAlgorithm.SHA256;
- }
- }
-
- /**
- * Method getDataSource.
-
- * @return DataSourceType */
- private static DataSourceType getDataSource() {
- String key = "DataSource.backend";
- try {
- return DataSource.DataSourceType.valueOf(configFile.getString(key, "sqlite").toUpperCase());
- } catch (IllegalArgumentException ex) {
- ConsoleLogger.showError("Unknown database backend; defaulting to SQLite database");
- return DataSource.DataSourceType.SQLITE;
- }
- }
-
- /**
- * Config option for setting and check restricted user by username;ip ,
- * return false if ip and name doesn't match with player that join the
- * server, so player has a restricted access
- * @param name String
- * @param ip String
-
- * @return boolean */
- public static boolean getRestrictedIp(String name, String ip) {
-
- Iterator iterator = getRestrictedIp.iterator();
- boolean trueOnce = false;
- boolean nameFound = false;
- while(iterator.hasNext()) {
- String[] args = iterator.next().split(";");
- String testName = args[0];
- String testIp = args[1];
- if (testName.equalsIgnoreCase(name)) {
- nameFound = true;
- if (testIp.equalsIgnoreCase(ip)) {
- trueOnce = true;
- }
- }
- }
- return !nameFound || trueOnce;
- }
-
- /**
- * Saves the configuration to disk
- *
-
- * @return True if saved successfully */
- public static boolean save() {
- try {
- instance.save(SETTINGS_FILE);
- return true;
- } catch (Exception ex) {
- return false;
- }
- }
-
/**
* Saves current configuration (plus defaults) to disk.
*
* If defaults and configuration are empty, saves blank file.
*
-
- * @return True if saved successfully */
+ * @return True if saved successfully
+ */
public final boolean saveDefaults() {
options().copyDefaults(true);
options().copyHeader(true);
@@ -606,101 +698,4 @@ public final class Settings extends YamlConfiguration {
options().copyHeader(false);
return success;
}
-
- /**
- * Method checkLang.
- * @param lang String
-
- * @return String */
- public static String checkLang(String lang) {
- if (new File(PLUGIN_FOLDER, "messages" + File.separator + "messages_" + lang + ".yml").exists()) {
- ConsoleLogger.info("Set Language to: " + lang);
- return lang;
- }
- if (AuthMe.class.getResourceAsStream("/messages/messages_" + lang + ".yml") != null) {
- ConsoleLogger.info("Set Language to: " + lang);
- return lang;
- }
- ConsoleLogger.info("Language file not found for " + lang + ", set to default language: en !");
- return "en";
- }
-
- /**
- * Method switchAntiBotMod.
- * @param mode boolean
- */
- public static void switchAntiBotMod(boolean mode) {
- if (mode) {
- isKickNonRegisteredEnabled = true;
- antiBotInAction = true;
- } else {
- isKickNonRegisteredEnabled = configFile.getBoolean("settings.restrictions.kickNonRegistered", false);
- antiBotInAction = false;
- }
- }
-
- private static void getWelcomeMessage() {
- AuthMe plugin = AuthMe.getInstance();
- welcomeMsg = new ArrayList<>();
- if (!useWelcomeMessage) {
- return;
- }
- if (!(new File(plugin.getDataFolder() + File.separator + "welcome.txt").exists())) {
- try {
- FileWriter fw = new FileWriter(plugin.getDataFolder() + File.separator + "welcome.txt", true);
- BufferedWriter w = new BufferedWriter(fw);
- w.write("Welcome {PLAYER} on {SERVER} server");
- w.newLine();
- w.write("This server uses " + AuthMe.PLUGIN_NAME + " protection!");
- w.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- try {
- FileReader fr = new FileReader(plugin.getDataFolder() + File.separator + "welcome.txt");
- BufferedReader br = new BufferedReader(fr);
- String line;
- while ((line = br.readLine()) != null) {
- welcomeMsg.add(line);
- }
- br.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- /**
- * Method isEmailCorrect.
- * @param email String
-
- * @return boolean */
- public static boolean isEmailCorrect(String email) {
- if (!email.contains("@"))
- return false;
- if (email.equalsIgnoreCase("your@email.com"))
- return false;
- String emailDomain = email.split("@")[1];
- boolean correct = true;
- if (emailWhitelist != null && !emailWhitelist.isEmpty()) {
- for (String domain : emailWhitelist) {
- if (!domain.equalsIgnoreCase(emailDomain)) {
- correct = false;
- } else {
- correct = true;
- break;
- }
- }
- return correct;
- }
- if (emailBlacklist != null && !emailBlacklist.isEmpty()) {
- for (String domain : emailBlacklist) {
- if (domain.equalsIgnoreCase(emailDomain)) {
- correct = false;
- break;
- }
- }
- }
- return correct;
- }
}
diff --git a/src/main/java/fr/xephi/authme/settings/Spawn.java b/src/main/java/fr/xephi/authme/settings/Spawn.java
index 0671ceb48..a37e90ce2 100644
--- a/src/main/java/fr/xephi/authme/settings/Spawn.java
+++ b/src/main/java/fr/xephi/authme/settings/Spawn.java
@@ -1,12 +1,11 @@
package fr.xephi.authme.settings;
-import java.io.File;
-
import org.bukkit.Bukkit;
import org.bukkit.Location;
+import java.io.File;
+
/**
- *
* @author Xephi59
* @version $Revision: 1.0 $
*/
@@ -22,6 +21,18 @@ public class Spawn extends CustomConfiguration {
saveDefault();
}
+ /**
+ * Method getInstance.
+ *
+ * @return Spawn
+ */
+ public static Spawn getInstance() {
+ if (spawn == null) {
+ spawn = new Spawn();
+ }
+ return spawn;
+ }
+
private void saveDefault() {
if (!contains("spawn")) {
set("spawn.world", "");
@@ -43,22 +54,12 @@ public class Spawn extends CustomConfiguration {
}
}
- /**
- * Method getInstance.
-
- * @return Spawn */
- public static Spawn getInstance() {
- if (spawn == null) {
- spawn = new Spawn();
- }
- return spawn;
- }
-
/**
* Method setSpawn.
+ *
* @param location Location
-
- * @return boolean */
+ * @return boolean
+ */
public boolean setSpawn(Location location) {
try {
set("spawn.world", location.getWorld().getName());
@@ -76,9 +77,10 @@ public class Spawn extends CustomConfiguration {
/**
* Method setFirstSpawn.
+ *
* @param location Location
-
- * @return boolean */
+ * @return boolean
+ */
public boolean setFirstSpawn(Location location) {
try {
set("firstspawn.world", location.getWorld().getName());
@@ -96,8 +98,9 @@ public class Spawn extends CustomConfiguration {
/**
* Method getLocation.
-
- * @return Location */
+ *
+ * @return Location
+ */
@Deprecated
public Location getLocation() {
return getSpawn();
@@ -105,8 +108,9 @@ public class Spawn extends CustomConfiguration {
/**
* Method getSpawn.
-
- * @return Location */
+ *
+ * @return Location
+ */
public Location getSpawn() {
try {
if (this.getString("spawn.world").isEmpty() || this.getString("spawn.world").equals(""))
@@ -120,8 +124,9 @@ public class Spawn extends CustomConfiguration {
/**
* Method getFirstSpawn.
-
- * @return Location */
+ *
+ * @return Location
+ */
public Location getFirstSpawn() {
try {
if (this.getString("firstspawn.world").isEmpty() || this.getString("firstspawn.world").equals(""))
diff --git a/src/main/java/fr/xephi/authme/task/ChangePasswordTask.java b/src/main/java/fr/xephi/authme/task/ChangePasswordTask.java
index 77a1155ec..c7929b6e3 100644
--- a/src/main/java/fr/xephi/authme/task/ChangePasswordTask.java
+++ b/src/main/java/fr/xephi/authme/task/ChangePasswordTask.java
@@ -1,9 +1,5 @@
package fr.xephi.authme.task;
-import java.security.NoSuchAlgorithmException;
-
-import org.bukkit.entity.Player;
-
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth;
@@ -11,6 +7,9 @@ import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings;
+import org.bukkit.entity.Player;
+
+import java.security.NoSuchAlgorithmException;
/**
*/
@@ -23,8 +22,9 @@ public class ChangePasswordTask implements Runnable {
/**
* Constructor for ChangePasswordTask.
- * @param plugin AuthMe
- * @param player Player
+ *
+ * @param plugin AuthMe
+ * @param player Player
* @param oldPassword String
* @param newPassword String
*/
@@ -37,6 +37,7 @@ public class ChangePasswordTask implements Runnable {
/**
* Method run.
+ *
* @see java.lang.Runnable#run()
*/
@Override
diff --git a/src/main/java/fr/xephi/authme/task/MessageTask.java b/src/main/java/fr/xephi/authme/task/MessageTask.java
index af9474403..1540e1dc2 100644
--- a/src/main/java/fr/xephi/authme/task/MessageTask.java
+++ b/src/main/java/fr/xephi/authme/task/MessageTask.java
@@ -1,12 +1,11 @@
package fr.xephi.authme.task;
-import org.bukkit.entity.Player;
-import org.bukkit.scheduler.BukkitTask;
-
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.cache.limbo.LimboCache;
import fr.xephi.authme.util.Utils;
+import org.bukkit.entity.Player;
+import org.bukkit.scheduler.BukkitTask;
/**
*/
@@ -19,9 +18,10 @@ public class MessageTask implements Runnable {
/**
* Constructor for MessageTask.
- * @param plugin AuthMe
- * @param name String
- * @param strings String[]
+ *
+ * @param plugin AuthMe
+ * @param name String
+ * @param strings String[]
* @param interval int
*/
public MessageTask(AuthMe plugin, String name, String[] strings,
@@ -34,6 +34,7 @@ public class MessageTask implements Runnable {
/**
* Method run.
+ *
* @see java.lang.Runnable#run()
*/
@Override
diff --git a/src/main/java/fr/xephi/authme/task/TimeoutTask.java b/src/main/java/fr/xephi/authme/task/TimeoutTask.java
index 4fed35837..8cbad2903 100644
--- a/src/main/java/fr/xephi/authme/task/TimeoutTask.java
+++ b/src/main/java/fr/xephi/authme/task/TimeoutTask.java
@@ -1,11 +1,10 @@
package fr.xephi.authme.task;
-import org.bukkit.Bukkit;
-import org.bukkit.entity.Player;
-
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.settings.Messages;
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
/**
*/
@@ -18,8 +17,9 @@ public class TimeoutTask implements Runnable {
/**
* Constructor for TimeoutTask.
+ *
* @param plugin AuthMe
- * @param name String
+ * @param name String
* @param player Player
*/
public TimeoutTask(AuthMe plugin, String name, Player player) {
@@ -30,14 +30,16 @@ public class TimeoutTask implements Runnable {
/**
* Method getName.
-
- * @return String */
+ *
+ * @return String
+ */
public String getName() {
return name;
}
/**
* Method run.
+ *
* @see java.lang.Runnable#run()
*/
@Override
diff --git a/src/main/java/fr/xephi/authme/util/GeoLiteAPI.java b/src/main/java/fr/xephi/authme/util/GeoLiteAPI.java
new file mode 100644
index 000000000..76bd9d8c7
--- /dev/null
+++ b/src/main/java/fr/xephi/authme/util/GeoLiteAPI.java
@@ -0,0 +1,96 @@
+package fr.xephi.authme.util;
+
+import com.maxmind.geoip.LookupService;
+import fr.xephi.authme.AuthMe;
+import fr.xephi.authme.ConsoleLogger;
+import fr.xephi.authme.settings.Settings;
+
+import java.io.*;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.zip.GZIPInputStream;
+
+public class GeoLiteAPI {
+
+ private static final String GEOIP_URL = "http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry" +
+ "/GeoIP.dat.gz";
+ private static final AuthMe plugin = AuthMe.getInstance();
+ private static LookupService lookupService;
+
+ /**
+ * Download (if absent) the GeoIpLite data file and then try to load it.
+ *
+ * @return Boolean True if the data is available, false if not.
+ */
+ public static boolean isDataAvailable() {
+ if (lookupService != null) {
+ return true;
+ }
+ final File data = new File(Settings.PLUGIN_FOLDER, "GeoIP.dat");
+ if (data.exists()) {
+ try {
+ lookupService = new LookupService(data);
+ plugin.getLogger().info("[LICENSE] This product uses data from the GeoLite API created by MaxMind, " +
+ "available at http://www.maxmind.com");
+ return true;
+ } catch (IOException e) {
+ return false;
+ }
+ }
+ // Ok, let's try to download the data file!
+ plugin.getGameServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
+ @Override
+ public void run() {
+ try {
+ URL downloadUrl = new URL(GEOIP_URL);
+ URLConnection conn = downloadUrl.openConnection();
+ conn.setConnectTimeout(10000);
+ conn.connect();
+ InputStream input = conn.getInputStream();
+ if (conn.getURL().toString().endsWith(".gz")) {
+ input = new GZIPInputStream(input);
+ }
+ OutputStream output = new FileOutputStream(data);
+ byte[] buffer = new byte[2048];
+ int length = input.read(buffer);
+ while (length >= 0) {
+ output.write(buffer, 0, length);
+ length = input.read(buffer);
+ }
+ output.close();
+ input.close();
+ } catch (IOException e) {
+ ConsoleLogger.writeStackTrace(e);
+ }
+ }
+ });
+ return false;
+ }
+
+ /**
+ * Get the country code of the given IP address.
+ *
+ * @param ip Ip address
+ * @return String
+ */
+ public static String getCountryCode(String ip) {
+ if (isDataAvailable()) {
+ return lookupService.getCountry(ip).getCode();
+ }
+ return "--";
+ }
+
+ /**
+ * Get the country name of the given IP address.
+ *
+ * @param ip Ip address
+ * @return String
+ */
+ public static String getCountryName(String ip) {
+ if (isDataAvailable()) {
+ return lookupService.getCountry(ip).getName();
+ }
+ return "N/A";
+ }
+
+}
diff --git a/src/main/java/fr/xephi/authme/util/Profiler.java b/src/main/java/fr/xephi/authme/util/Profiler.java
index 92e3c51fb..0784aa653 100644
--- a/src/main/java/fr/xephi/authme/util/Profiler.java
+++ b/src/main/java/fr/xephi/authme/util/Profiler.java
@@ -7,9 +7,13 @@ import java.text.DecimalFormat;
@SuppressWarnings("UnusedDeclaration")
public class Profiler {
- /** Defines the past time in milliseconds. */
+ /**
+ * Defines the past time in milliseconds.
+ */
private long time = 0;
- /** Defines the time in milliseconds the profiler last started at. */
+ /**
+ * Defines the time in milliseconds the profiler last started at.
+ */
private long start = -1;
/**
@@ -26,19 +30,19 @@ public class Profiler {
*/
public Profiler(boolean start) {
// Should the timer be started
- if(start)
+ if (start)
start();
}
/**
* Start the profiler.
*
-
* @return True if the profiler was started, false otherwise possibly due to an error.
- * True will also be returned if the profiler was started already. */
+ * True will also be returned if the profiler was started already.
+ */
public boolean start() {
// Make sure the timer isn't started already
- if(isActive())
+ if (isActive())
return true;
// Set the start time
@@ -49,11 +53,11 @@ public class Profiler {
/**
* This will start the profiler if it's not active, or will stop the profiler if it's currently active.
*
-
- * @return True if the profiler has been started, false if the profiler has been stopped. */
+ * @return True if the profiler has been started, false if the profiler has been stopped.
+ */
public boolean pause() {
// Toggle the profiler state
- if(isStarted())
+ if (isStarted())
stop();
else
start();
@@ -65,12 +69,12 @@ public class Profiler {
/**
* Stop the profiler if it's active.
*
-
* @return True will be returned if the profiler was stopped while it was active. False will be returned if the
- * profiler was stopped already. */
+ * profiler was stopped already.
+ */
public boolean stop() {
// Make sure the profiler is active
- if(!isActive())
+ if (!isActive())
return false;
// Stop the profiler, calculate the passed time
@@ -82,8 +86,8 @@ public class Profiler {
/**
* Check whether the profiler has been started. The profiler doesn't need to be active right now.
*
-
- * @return True if the profiler was started, false otherwise. */
+ * @return True if the profiler was started, false otherwise.
+ */
public boolean isStarted() {
return isActive() || this.time > 0;
}
@@ -91,8 +95,8 @@ public class Profiler {
/**
* Check whether the profiler is currently active.
*
-
- * @return True if the profiler is active, false otherwise. */
+ * @return True if the profiler is active, false otherwise.
+ */
public boolean isActive() {
return this.start >= 0;
}
@@ -100,11 +104,11 @@ public class Profiler {
/**
* Get the passed time in milliseconds.
*
-
- * @return The passed time in milliseconds. */
+ * @return The passed time in milliseconds.
+ */
public long getTime() {
// Check whether the profiler is currently active
- if(isActive())
+ if (isActive())
return this.time + (System.currentTimeMillis() - this.start);
return this.time;
}
@@ -112,18 +116,18 @@ public class Profiler {
/**
* Get the passed time in a formatted string.
*
-
- * @return The passed time in a formatted string. */
+ * @return The passed time in a formatted string.
+ */
public String getTimeFormatted() {
// Get the passed time
long time = getTime();
// Return the time if it's less than one millisecond
- if(time <= 0)
+ if (time <= 0)
return "<1 ms";
// Return the time in milliseconds
- if(time < 1000)
+ if (time < 1000)
return time + " ms";
// Convert the time into seconds with a single decimal
diff --git a/src/main/java/fr/xephi/authme/util/StringUtils.java b/src/main/java/fr/xephi/authme/util/StringUtils.java
index c5d34c578..c5c0f6e8f 100644
--- a/src/main/java/fr/xephi/authme/util/StringUtils.java
+++ b/src/main/java/fr/xephi/authme/util/StringUtils.java
@@ -12,17 +12,18 @@ import java.io.StringWriter;
*/
public class StringUtils {
+ public static final String newline = System.getProperty("line.separator");
+
/**
* Get the difference of two strings.
*
- * @param first First string
+ * @param first First string
* @param second Second string
- *
* @return The difference value
*/
public static double getDifference(String first, String second) {
// Make sure the strings are valid.
- if(first == null || second == null)
+ if (first == null || second == null)
return 1.0;
// Create a string similarity service instance, to allow comparison
@@ -35,21 +36,20 @@ public class StringUtils {
/**
* Returns whether the given string contains any of the provided elements.
*
- * @param str the string to analyze
+ * @param str the string to analyze
* @param pieces the items to check the string for
- *
* @return true if the string contains at least one of the items
*/
public static boolean containsAny(String str, String... pieces) {
- if (str == null) {
- return false;
- }
- for (String piece : pieces) {
- if (piece != null && str.contains(piece)) {
- return true;
- }
- }
- return false;
+ if (str == null) {
+ return false;
+ }
+ for (String piece : pieces) {
+ if (piece != null && str.contains(piece)) {
+ return true;
+ }
+ }
+ return false;
}
/**
@@ -57,7 +57,6 @@ public class StringUtils {
* is trimmed, so this method also considers a string with whitespace as empty.
*
* @param str the string to verify
- *
* @return true if the string is empty, false otherwise
*/
public static boolean isEmpty(String str) {
@@ -68,8 +67,7 @@ public class StringUtils {
* Joins a list of elements into a single string with the specified delimiter.
*
* @param delimiter the delimiter to use
- * @param elements the elements to join
- *
+ * @param elements the elements to join
* @return a new String that is composed of the elements separated by the delimiter
*/
public static String join(String delimiter, Iterable elements) {
@@ -91,7 +89,6 @@ public class StringUtils {
* Get a full stack trace of an exception as a string.
*
* @param exception The exception.
- *
* @return Stack trace as a string.
*/
public static String getStackTrace(Exception exception) {
diff --git a/src/main/java/fr/xephi/authme/util/Utils.java b/src/main/java/fr/xephi/authme/util/Utils.java
index 6623c8dc0..3262f2f5e 100644
--- a/src/main/java/fr/xephi/authme/util/Utils.java
+++ b/src/main/java/fr/xephi/authme/util/Utils.java
@@ -95,45 +95,30 @@ public final class Utils {
return false;
}
- public static String getCountryCode(String ip) {
- if (checkGeoIP()) {
- return lookupService.getCountry(ip).getCode();
- }
- return "--";
- }
-
- public static String getCountryName(String ip) {
- if (checkGeoIP()) {
- return lookupService.getCountry(ip).getName();
- }
- return "N/A";
- }
-
/**
* Set the group of a player, by its AuthMe group type.
*
* @param player The player.
- * @param group The group type.
- *
- * @return True if succeed, false otherwise.
- * False is also returned if groups aren't supported with the current permissions system.
+ * @param group The group type.
+ * @return True if succeed, false otherwise. False is also returned if groups aren't supported
+ * with the current permissions system.
*/
public static boolean setGroup(Player player, GroupType group) {
// Check whether the permissions check is enabled
- if(!Settings.isPermissionCheckEnabled)
+ if (!Settings.isPermissionCheckEnabled)
return false;
// Get the permissions manager, and make sure it's valid
PermissionsManager permsMan = plugin.getPermissionsManager();
- if(permsMan == null)
+ if (permsMan == null)
ConsoleLogger.showError("Failed to access permissions manager instance, shutting down.");
assert permsMan != null;
// Make sure group support is available
- if(!permsMan.hasGroupSupport())
+ if (!permsMan.hasGroupSupport())
ConsoleLogger.showError("The current permissions system doesn't have group support, unable to set group!");
- switch(group) {
+ switch (group) {
case UNREGISTERED:
// Remove the other group type groups, set the current group
permsMan.removeGroups(player, Arrays.asList(Settings.getRegisteredGroup, Settings.getUnloggedinGroup));
@@ -152,7 +137,7 @@ public final class Utils {
case LOGGEDIN:
// Get the limbo player data
LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(player.getName().toLowerCase());
- if(limbo == null)
+ if (limbo == null)
return false;
// Get the players group
@@ -169,21 +154,20 @@ public final class Utils {
/**
* TODO: This method requires better explanation.
- *
+ *
* Set the normal group of a player.
*
* @param player The player.
- * @param group The normal group.
-
+ * @param group The normal group.
* @return True on success, false on failure.
*/
public static boolean addNormal(Player player, String group) {
- if(!Settings.isPermissionCheckEnabled)
+ if (!Settings.isPermissionCheckEnabled)
return false;
// Get the permissions manager, and make sure it's valid
PermissionsManager permsMan = plugin.getPermissionsManager();
- if(permsMan == null)
+ if (permsMan == null)
ConsoleLogger.showError("Failed to access permissions manager instance, shutting down.");
assert permsMan != null;
@@ -221,10 +205,11 @@ public final class Utils {
/**
* Method packCoords.
- * @param x double
- * @param y double
- * @param z double
- * @param w String
+ *
+ * @param x double
+ * @param y double
+ * @param z double
+ * @param w String
* @param pl Player
*/
public static void packCoords(double x, double y, double z, String w,
@@ -265,40 +250,35 @@ public final class Utils {
}
/**
+ * Delete a given directory and all his content.
+ *
+ * @param directory File
*/
- public enum GroupType {
- UNREGISTERED,
- REGISTERED,
- NOTLOGGEDIN,
- LOGGEDIN
- }
-
- public static void purgeDirectory(File file) {
- if (!file.isDirectory()) {
+ public static void purgeDirectory(File directory) {
+ if (!directory.isDirectory()) {
return;
}
- File[] files = file.listFiles();
+ File[] files = directory.listFiles();
if (files == null) {
return;
}
for (File target : files) {
if (target.isDirectory()) {
purgeDirectory(target);
- target.delete();
- } else {
- target.delete();
}
+ target.delete();
}
}
/**
- * Safe way to retrieve the list of online players from the server. Depending on the implementation
- * of the server, either an array of {@link Player} instances is being returned, or a Collection.
- * Always use this wrapper to retrieve online players instead of {@link Bukkit#getOnlinePlayers()} directly.
+ * Safe way to retrieve the list of online players from the server. Depending on the
+ * implementation of the server, either an array of {@link Player} instances is being returned,
+ * or a Collection. Always use this wrapper to retrieve online players instead of {@link
+ * Bukkit#getOnlinePlayers()} directly.
*
* @return collection of online players
- *
- * @see SpigotMC forum
+ * @see SpigotMC
+ * forum
* @see StackOverflow
*/
@SuppressWarnings("unchecked")
@@ -309,7 +289,7 @@ public final class Utils {
try {
// The lookup of a method via Reflections is rather expensive, so we keep a reference to it
if (getOnlinePlayers == null) {
- getOnlinePlayers = Bukkit.class.getMethod("getOnlinePlayers");
+ getOnlinePlayers = Bukkit.class.getDeclaredMethod("getOnlinePlayers");
}
Object obj = getOnlinePlayers.invoke(null);
if (obj instanceof Collection>) {
@@ -328,8 +308,8 @@ public final class Utils {
}
/**
- * Method run when the Utils class is loaded to verify whether or not the Bukkit
- * implementation returns the online players as a Collection.
+ * Method run when the Utils class is loaded to verify whether or not the Bukkit implementation
+ * returns the online players as a Collection.
*
* @see Utils#getOnlinePlayers()
*/
@@ -373,4 +353,13 @@ public final class Utils {
}
}
}
+
+ /**
+ */
+ public enum GroupType {
+ UNREGISTERED,
+ REGISTERED,
+ NOTLOGGEDIN,
+ LOGGEDIN
+ }
}