Generating encrypted passwords
This recipe explains how to protect the plain text password using different hashing algorithms with or without using salt.
Getting started
Use the same ch04
project, applying a different security model which focuses on how to inject an encryption algorithm into the security container to enable password encoding and matching during the authentication process.
How to do it...
The following recipe shows how to create an encrypted password:
- To implement an encrypted authentication, let us start with a custom class,
AppPasswordEncoder
, that serves as a compendium of some popularPasswordEncoder
APIs:
public class AppPasswordEncoder { public String md5Encoder(String password, String salt) { Md5PasswordEncoder md5PasswordEncoder = new Md5PasswordEncoder(); md5PasswordEncoder.setEncodeHashAsBase64(true); md5PasswordEncoder.setIterations(32); String encoded = md5PasswordEncoder.encodePassword(password,salt); return encoded...