Merge branch 'develop' into feature/jakrtaee10
# Conflicts: # configuration/pom.xml # db/pom.xml # jeeutil/pom.xml # network/pom.xml # poi-util/pom.xml # pom.xml # util/pom.xml
This commit is contained in:
72
util/pom.xml
72
util/pom.xml
@ -1,4 +1,3 @@
|
||||
|
||||
<!--
|
||||
Copyright 2019 Joern Muehlencord (joern@muehlencord.de).
|
||||
|
||||
@ -14,41 +13,42 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>de.muehlencord.shared</groupId>
|
||||
<artifactId>shared-util</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>shared-util</name>
|
||||
|
||||
<parent>
|
||||
<artifactId>shared</artifactId>
|
||||
<groupId>de.muehlencord</groupId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
|
||||
<url>http://maven.apache.org</url>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<groupId>de.muehlencord.shared</groupId>
|
||||
<artifactId>shared-util</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<name>shared-util</name>
|
||||
|
||||
<parent>
|
||||
<artifactId>shared</artifactId>
|
||||
<groupId>de.muehlencord</groupId>
|
||||
<version>2.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
|
||||
<url>http://maven.apache.org</url>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* Copyright 2019 Joern Muehlencord (joern@muehlencord.de).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -15,45 +15,46 @@
|
||||
*/
|
||||
package de.muehlencord.shared.util;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import org.bouncycastle.util.encoders.Base64;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Joern Muehlencord (joern@muehlencord.de)
|
||||
*/
|
||||
public class PasswordUtilTest {
|
||||
|
||||
private static SecureRandom secureRandom;
|
||||
private static String systemSalt64Coded;
|
||||
private static byte[] systemSaltBytes;
|
||||
|
||||
@BeforeAll
|
||||
public static void init() {
|
||||
secureRandom = new SecureRandom();
|
||||
|
||||
systemSaltBytes = new byte[32];
|
||||
secureRandom.nextBytes (systemSaltBytes);
|
||||
systemSalt64Coded = new String(Base64.encode (systemSaltBytes));
|
||||
}
|
||||
|
||||
class PasswordUtilTest {
|
||||
|
||||
@Test
|
||||
public void testGetHash() {
|
||||
PasswordUtil pwUtil = new PasswordUtil(systemSalt64Coded);
|
||||
|
||||
String password1 = pwUtil.getHash("password");
|
||||
String password2 = pwUtil.getHash("password");
|
||||
|
||||
assertFalse (password1.equals(password2));
|
||||
assertTrue (pwUtil.matches ("password", password1));
|
||||
assertFalse (pwUtil.matches ("wrongpassword", password1));
|
||||
|
||||
private static SecureRandom secureRandom;
|
||||
private static String systemSalt64Coded;
|
||||
private static byte[] systemSaltBytes;
|
||||
|
||||
@BeforeAll
|
||||
public static void init() {
|
||||
secureRandom = new SecureRandom();
|
||||
|
||||
systemSaltBytes = new byte[32];
|
||||
secureRandom.nextBytes(systemSaltBytes);
|
||||
systemSalt64Coded = new String(Base64.encode(systemSaltBytes));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testGetHash() {
|
||||
PasswordUtil pwUtil = new PasswordUtil(systemSalt64Coded);
|
||||
|
||||
String password1 = pwUtil.getHash("password");
|
||||
String password2 = pwUtil.getHash("password");
|
||||
|
||||
assertNotEquals(password1, password2);
|
||||
assertTrue(pwUtil.matches("password", password1));
|
||||
assertFalse(pwUtil.matches("wrongpassword", password1));
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user