diff --git a/src/main/java/fr/xephi/authme/api/API.java b/src/main/java/fr/xephi/authme/api/API.java index 7fe3d43ed..e849e7950 100644 --- a/src/main/java/fr/xephi/authme/api/API.java +++ b/src/main/java/fr/xephi/authme/api/API.java @@ -157,10 +157,7 @@ public class API { return false; } PlayerAuth auth = new PlayerAuth(name, hash, "198.18.0.1", 0, "your@email.com", playerName); - if (!instance.database.saveAuth(auth)) { - return false; - } - return true; + return instance.database.saveAuth(auth); } catch (NoSuchAlgorithmException ex) { return false; } diff --git a/src/main/java/fr/xephi/authme/datasource/FlatFile.java b/src/main/java/fr/xephi/authme/datasource/FlatFile.java index 9901a0fa3..19c93ea3a 100644 --- a/src/main/java/fr/xephi/authme/datasource/FlatFile.java +++ b/src/main/java/fr/xephi/authme/datasource/FlatFile.java @@ -744,9 +744,10 @@ public class FlatFile implements DataSource { for (String l : lines) { bw.write(l + "\n"); } + } catch (IOException ex) { ConsoleLogger.showError(ex.getMessage()); - return; + } finally { if (br != null) { try { @@ -761,7 +762,6 @@ public class FlatFile implements DataSource { } } } - return; } /** 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 c93171af1..cdf256a99 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/CryptPBKDF2.java +++ b/src/main/java/fr/xephi/authme/security/crypts/CryptPBKDF2.java @@ -4,6 +4,7 @@ import fr.xephi.authme.security.pbkdf2.PBKDF2Engine; import fr.xephi.authme.security.pbkdf2.PBKDF2Parameters; import java.security.NoSuchAlgorithmException; +import java.util.Arrays; /** */ @@ -25,7 +26,7 @@ public class CryptPBKDF2 implements EncryptionMethod { PBKDF2Parameters params = new PBKDF2Parameters("HmacSHA256", "ASCII", salt.getBytes(), 10000); PBKDF2Engine engine = new PBKDF2Engine(params); - return result + String.valueOf(engine.deriveKey(password, 64)); + return result + Arrays.toString(engine.deriveKey(password, 64)); } /** 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 c66a42ec3..d1dab3025 100644 --- a/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2.java +++ b/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2.java @@ -41,7 +41,7 @@ public interface PBKDF2 { * * @return internal byte array */ - public abstract byte[] deriveKey(String inputPassword); + byte[] deriveKey(String inputPassword); /** * Convert String-based input to internal byte array, then invoke PBKDF2. @@ -51,7 +51,7 @@ public interface PBKDF2 { * * @return internal byte array */ - public abstract byte[] deriveKey(String inputPassword, int dkLen); + byte[] deriveKey(String inputPassword, int dkLen); /** * Convert String-based input to internal byte arrays, then invoke PBKDF2 @@ -63,28 +63,28 @@ public interface PBKDF2 { * @return true password match; false incorrect * password */ - public abstract boolean verifyKey(String inputPassword); + boolean verifyKey(String inputPassword); /** * Allow reading of configured parameters. * * @return Currently set parameters. */ - public abstract PBKDF2Parameters getParameters(); + PBKDF2Parameters getParameters(); /** * Allow setting of configured parameters. * * @param parameters */ - public abstract void setParameters(PBKDF2Parameters parameters); + void setParameters(PBKDF2Parameters parameters); /** * Get currently set Pseudo Random Function. * * @return Currently set Pseudo Random Function */ - public abstract PRF getPseudoRandomFunction(); + PRF getPseudoRandomFunction(); /** * Set the Pseudo Random Function to use. Note that deriveKeys/getPRF does @@ -93,5 +93,5 @@ public interface PBKDF2 { * * @param prf Pseudo Random Function to set. */ - public abstract void setPseudoRandomFunction(PRF prf); + void setPseudoRandomFunction(PRF prf); } 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 dc82ea208..3916d1c03 100644 --- a/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2Formatter.java +++ b/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2Formatter.java @@ -40,7 +40,7 @@ public interface PBKDF2Formatter { * * @return String representation */ - public abstract String toString(PBKDF2Parameters p); + String toString(PBKDF2Parameters p); /** * Convert String to parameters. Depending on actual implementation, it may @@ -52,5 +52,5 @@ public interface PBKDF2Formatter { * @return false syntax OK, true some syntax * issue. */ - public abstract boolean fromString(PBKDF2Parameters p, String s); + 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 ed07217ff..2309d77f1 100644 --- a/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2HexFormatter.java +++ b/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2HexFormatter.java @@ -47,7 +47,7 @@ public class PBKDF2HexFormatter implements PBKDF2Formatter { } String[] p123 = s.split(":"); - if (p123 == null || p123.length != 3) { + if (p123.length != 3) { return true; } 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 408588c6d..af40e171d 100644 --- a/src/main/java/fr/xephi/authme/security/pbkdf2/PRF.java +++ b/src/main/java/fr/xephi/authme/security/pbkdf2/PRF.java @@ -39,7 +39,7 @@ public interface PRF { * @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); + void init(byte[] P); /** * Pseudo Random Function @@ -49,12 +49,12 @@ public interface PRF { * * @return Random bytes of hLen length. */ - public byte[] doFinal(byte[] M); + byte[] doFinal(byte[] M); /** * Query block size of underlying algorithm/mechanism. * * @return block size */ - public int getHLen(); + int getHLen(); } diff --git a/src/main/java/fr/xephi/authme/util/Utils.java b/src/main/java/fr/xephi/authme/util/Utils.java index 1a83b570e..0ff0867f8 100644 --- a/src/main/java/fr/xephi/authme/util/Utils.java +++ b/src/main/java/fr/xephi/authme/util/Utils.java @@ -268,6 +268,7 @@ public final class Utils { if (target.isDirectory()) { purgeDirectory(target); } + //noinspection ResultOfMethodCallIgnored target.delete(); } } diff --git a/src/test/java/fr/xephi/authme/util/UtilsTest.java b/src/test/java/fr/xephi/authme/util/UtilsTest.java index cb1ed19ad..085e5b273 100644 --- a/src/test/java/fr/xephi/authme/util/UtilsTest.java +++ b/src/test/java/fr/xephi/authme/util/UtilsTest.java @@ -25,15 +25,12 @@ import static org.mockito.Mockito.when; */ public class UtilsTest { - private AuthMe authMeMock; - private PermissionsManager permissionsManagerMock; - @Before public void setUpMocks() { AuthMeMockUtil.mockAuthMeInstance(); - authMeMock = AuthMe.getInstance(); + AuthMe authMeMock = AuthMe.getInstance(); - permissionsManagerMock = mock(PermissionsManager.class); + PermissionsManager permissionsManagerMock = mock(PermissionsManager.class); when(authMeMock.getPermissionsManager()).thenReturn(permissionsManagerMock); Server serverMock = mock(Server.class);