O'Reilly logo

Instant Java Password and Authentication Security by Fernando Mayoral

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a secure hash (Advanced)

This recipe teaches us how to create a truly secure strong hash and how to strengthen it as computers becomes more capable of breaking it.

There are libraries that provide secure hash functionality, but we are going to use a standard, plain java algorithm named PBKDF2WithHmacSHA1. So, we won't need any third-party libraries.

How to do it...

To create the first hash (Sign up), follow the given steps:

  1. Get the password as a char array.
  2. Create a salt value.
  3. Create a password based encryption key spec.
  4. Create a key factory.
  5. Generate the hash.
  6. Add the iterations and the original salt to your hash.

To generate a strong hash, please consider the code shown in the following screenshot:

We can test it by running the code shown in ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required