<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>
<groupId>NilPointer</groupId>
<artifactId>NilPointer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.mindrot</groupId>
<artifactId>jbcrypt</artifactId>
<version>0.4</version>
</dependency>
</dependencies>
</project>
package nilpointer.net;
import org.mindrot.jbcrypt.BCrypt;
public class Demo {
public static void main(String[] args) {
String password = "abc123";
String hash = BCrypt.hashpw(password, BCrypt.gensalt());
System.out.println("hash: " + hash);
String s1 = "def";
boolean result1 = BCrypt.checkpw(s1, hash);
System.out.println("result 1: " + result1);
String s2 = "abc123";
boolean result2 = BCrypt.checkpw(s2, hash);
System.out.println("result 2: " + result2);
}
}
hash: $2a$10$6Rtp4bITsnR6TlSCjGl1Q.lVhWAWvOM2ppw5JKGHSJ4P/DN0so10m
result 1: false
result 2: true