import org.springframework.security.crypto.bcrypt.BCrypt; /** 验证 Java BCrypt 能否校验 PHP password_hash() 生成的 $2y$ 口令 */ public class BcryptCheck { public static void main(String[] args) { String raw = args[0]; String hash = args[1]; System.out.println("hash prefix : " + hash.substring(0, 7)); System.out.println("正确密码 : " + BCrypt.checkpw(raw, hash)); System.out.println("错误密码 : " + BCrypt.checkpw(raw + "x", hash)); } }