Skip to content

Instantly share code, notes, and snippets.

@firaja
Created October 6, 2022 09:38
Show Gist options
  • Save firaja/26efc640937259941a05e9d518fb3a0e to your computer and use it in GitHub Desktop.
Save firaja/26efc640937259941a05e9d518fb3a0e to your computer and use it in GitHub Desktop.
Password4j - migrate from bcrypt to Argon2
String userPassword = "my password";
String oldHash = "$2y$06$pWbj0v7UGWgOp1mXWfCt1OUAibk5luL758NoVndquXnXfH79zFTRG";
BcryptFunction bcrypt = BcryptFunction.getInstanceFromHash(oldHash);
Argon2Function argon2 = Argon2Function.getInstance(14, 20, 1, 32, Argon2.ID);
HashUpdate update = Password.check(userPassword, oldHash)
.andUpdate()
.with(bcrypt, argon2);
update.isVerified(); // true
update.getHash().getResult(); // $argon2id$v=19$m=14,t=20,p=1$$q0HEx1FUKkHo3FEgD6n+bg3fuWYKcPSYYMuKFl79yMI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment