Get started

Password4j official guide

Prerequisites

Password4j runs on Java 8 or higher by any vendor. You should not find any issue unless you are using a custom homemade JVM.

The minimum supported Android API level is 26.

Setup

If you are working on a Maven project, you can add the following dependency:

<dependency>
    <groupId>com.password4j</groupId>
    <artifactId>password4j</artifactId>
    <version>1.8.1</version>
</dependency>

If you are not using Maven directly, you can still use the dependency from Maven dependency

Gradle

Add to your build.gradle module dependencies:

repositories {
    mavenCentral()
}

dependencies {
    implementation 'com.password4j:password4j:1.8.1'
}

Scala SBT

Add to the managed dependencies of your build.sbt the latest version:

libraryDependencies += "com.password4j" % "password4j" % "1.8.1"

JAR

Or you can download the JAR here and include it under your classpath.

Happy hashing

public class MyService
{

    public void protectPassword(User user, String userPassword)
    {
        Hash hash = Password.hash(userPassword)
                            .addPepper("shared-secret")
                            .addRandomSalt(32)
                            .with2();

        save(user, hash.getResult());
    }
}