diff --git a/pom.xml b/pom.xml index 2d1606f3..7ef8c3eb 100644 --- a/pom.xml +++ b/pom.xml @@ -72,6 +72,12 @@ org.codehaus.mojo exec-maven-plugin 1.6.0 + + + org.slf4j + slf4j-jdk14 + + diff --git a/src/main/java/com/password4j/BCryptFunction.java b/src/main/java/com/password4j/BCryptFunction.java index 63d2761e..94f1c2be 100644 --- a/src/main/java/com/password4j/BCryptFunction.java +++ b/src/main/java/com/password4j/BCryptFunction.java @@ -539,20 +539,10 @@ private String hashPw(byte[] passwordb, String salt) int off; StringBuilder rs = new StringBuilder(); - if (salt == null) - { - throw new BadParametersException("salt cannot be null"); - } + internalChecks(salt); int saltLength = salt.length(); - if (saltLength < 28) - { - throw new BadParametersException("Invalid salt"); - } - - if (salt.charAt(0) != '$' || salt.charAt(1) != '2') - throw new BadParametersException("Invalid salt version"); if (salt.charAt(2) == '$') off = 3; else @@ -594,6 +584,22 @@ private String hashPw(byte[] passwordb, String salt) return rs.toString(); } + private static void internalChecks(String salt) + { + if (salt == null) + { + throw new BadParametersException("salt cannot be null"); + } + else if (salt.length() < 28) + { + throw new BadParametersException("Invalid salt"); + } + else if (salt.charAt(0) != '$' || salt.charAt(1) != '2') + { + throw new BadParametersException("Invalid salt version"); + } + } + private static String generateSalt(String prefix, int logRounds) { StringBuilder rs = new StringBuilder(); diff --git a/src/main/java/com/password4j/SystemChecker.java b/src/main/java/com/password4j/SystemChecker.java index d8932288..54c0275b 100644 --- a/src/main/java/com/password4j/SystemChecker.java +++ b/src/main/java/com/password4j/SystemChecker.java @@ -22,7 +22,6 @@ import org.slf4j.LoggerFactory; import java.util.List; -import java.util.Scanner; public class SystemChecker { @@ -34,8 +33,6 @@ public class SystemChecker private static final int WARMUP_ROUNDS = 20; - private static final Scanner SCANNER = new Scanner(System.in); - private SystemChecker() { // diff --git a/src/test/com/password4j/BCryptFunctionTest.java b/src/test/com/password4j/BCryptFunctionTest.java index 220eccbc..d874b4ef 100644 --- a/src/test/com/password4j/BCryptFunctionTest.java +++ b/src/test/com/password4j/BCryptFunctionTest.java @@ -347,9 +347,9 @@ private static String encodeBase64(byte[] d, int len) @Test public void testBase64EncodeSimpleByteArrays() { - Assert.assertEquals(encodeBase64(new byte[]{0}, 1), ".."); - Assert.assertEquals(encodeBase64(new byte[]{0, 0}, 2), "..."); - Assert.assertEquals(encodeBase64(new byte[]{0, 0, 0}, 3), "...."); + Assert.assertEquals("..", encodeBase64(new byte[]{0}, 1)); + Assert.assertEquals("...", encodeBase64(new byte[]{0, 0}, 2)); + Assert.assertEquals("....", encodeBase64(new byte[]{0, 0, 0}, 3)); } @Test