Skip to content

Commit

Permalink
#83: added banner
Browse files Browse the repository at this point in the history
  • Loading branch information
firaja committed Oct 18, 2022
1 parent e1d399c commit 9303e33
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 27 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.3</version>
<scope>test</scope>
</dependency>

</dependencies>

<distributionManagement>
Expand Down
26 changes: 2 additions & 24 deletions src/main/java/com/password4j/Hash.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,31 +256,9 @@ private static boolean areEquals(CharSequence cs1, CharSequence cs2)
}
else if (cs1 != null && cs2 != null)
{
if (cs1.length() != cs2.length())
{
return false;
}
else if (cs1 instanceof String && cs2 instanceof String)
{
return cs1.equals(cs2);
}
else
{
int length = cs1.length();
for(int i = 0; i < length; ++i)
{
if (cs1.charAt(i) != cs2.charAt(i))
{
return false;
}
}
return true;
}
}
else
{
return false;
return cs1.equals(cs2);
}
return false;
}

@Override
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/password4j/Password.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*/
package com.password4j;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* This class provides the two main operations on password: hash and verify.
* <p>
Expand All @@ -31,6 +34,12 @@
public class Password
{

private static final Logger LOGGER = LoggerFactory.getLogger(Password.class);

static {
Utils.printBanner();
}

private Password()
{
//
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/password4j/PropertyReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class PropertyReader

private static final Logger LOG = LoggerFactory.getLogger(PropertyReader.class);

private static final String FILE_NAME = "/psw4j.properties";
private static final String FILE_NAME = "psw4j.properties";

private static final String CONFIGURATION_KEY = "psw4j.configuration";

Expand Down Expand Up @@ -118,7 +118,7 @@ static void init()
InputStream in;
if (customPath == null || customPath.length() == 0)
{
in = getResource(FILE_NAME);
in = getResource('/' + FILE_NAME);
}
else
{
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/com/password4j/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package com.password4j;


import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
Expand All @@ -25,6 +26,7 @@
import java.nio.charset.StandardCharsets;
import java.security.*;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -552,4 +554,38 @@ static String randomPrintable(int count)
return builder.toString();
}

static void printBanner()
{
if (PropertyReader.readBoolean("global.banner", true))
{
String pbkdf2Banner;
List<String> pbkd2s = AlgorithmFinder.getAllPBKDF2Variants();
if (pbkd2s.size() > 0) {
pbkdf2Banner = "✅ PBKDF2-" + String.join("/", pbkd2s).replaceAll("PBKDF2WithHmac", "");
}
else
{
pbkdf2Banner = "❌ PBKDF2 <-- not supported by " + System.getProperty("java.vm.name");
}

String banner ="\n";
banner += " |\n" +
" | \033[0;1mPassword4j\033[0;0m\n" +
" + \\ .: v1.6.1 :.\n" +
" \\\\.G_.*=.\n" +
" `(H'/.\\| ✅ Argon2\n" +
" .>' (_--. ✅ scrypt\n" +
" _=/d ,^\\ ✅ bcrypt\n" +
" ~~ \\)-'-' " + pbkdf2Banner + "\n" +
" / |\n" +
" ' '";
banner += "\n";
banner += " ⭐ If you enjoy Password4j, please star the project at https://github.com/Password4j/password4j\n";
banner += " \uD83D\uDC1B Report any issue at https://github.com/Password4j/password4j/issues\n";

System.out.println(banner);

}
}

}
3 changes: 3 additions & 0 deletions src/test/com/password4j/HashTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,16 @@ public void testSecFunc()
String toString2 = hash2.toString();
int hc2 = hash2.hashCode();
String toString3 = hash3.toString();
Hash hash4 = new Hash(hash3.getHashingFunction(), hash3.getResult(), hash3.getBytes(), hash3.getSalt());


// THEN
Assert.assertNotNull(toString1);
Assert.assertNotNull(toString2);
Assert.assertNotEquals(toString1, toString2);
Assert.assertNotEquals(toString3, toString2);
Assert.assertNotEquals(hc1, hc2);
Assert.assertNotEquals(hash4, hash3);
}

}
2 changes: 1 addition & 1 deletion src/test/com/password4j/PasswordTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ public void real()
.addPepper("shared-secret")
.with(bcrypt);

System.out.println(verified);
Assert.assertTrue(verified);
}

}

0 comments on commit 9303e33

Please sign in to comment.