Package com.jk.core.security
Class JKPasswordHash
java.lang.Object
com.jk.core.security.JKPasswordHash
This class provides methods for encoding and verifying passwords using the
BCrypt hashing algorithm.
Implementation of PasswordEncoder that uses the BCrypt strong hashing function.
Clients can optionally supply a "strength" (a.k.a. log rounds in BCrypt) and a SecureRandom instance.
The larger the strength parameter the more work will have to be done (exponentially) to hash the passwords.
The default value is 10.
- Version:
- 1.0
- Author:
- Dr. Jalal H. Kiswani, Dave Syer
-
Constructor Summary
ConstructorsConstructorDescriptionThis method constructs a newJKPasswordHash
with default strength of (-1) and the random instance is set to nullJKPasswordHash
(int strength) This method constructs a newJKPasswordHash
with the provided strength and the random instance is set to null.JKPasswordHash
(int strength, SecureRandom random) This method constructs a newJKPasswordHash
with the specified strength and the random instance is set to the provided instance. -
Method Summary
Modifier and TypeMethodDescriptionencode
(CharSequence rawPassword) This method hashes the provided rawPassword using BCrypt and returns the encoded password.boolean
matches
(CharSequence rawPassword, String encodedPassword) This method checks if the provided rawPassword matches the encodedPassword using BCrypt.
-
Constructor Details
-
JKPasswordHash
public JKPasswordHash()This method constructs a newJKPasswordHash
with default strength of (-1) and the random instance is set to null -
JKPasswordHash
public JKPasswordHash(int strength) This method constructs a newJKPasswordHash
with the provided strength and the random instance is set to null.- Parameters:
strength
- Specifies the strength parameter for BCrypt hashing.
-
JKPasswordHash
This method constructs a newJKPasswordHash
with the specified strength and the random instance is set to the provided instance.- Parameters:
strength
- Specifies the strength parameter for BCrypt hashing.random
- Specifies theSecureRandom
instance to use for generating salts.
-
-
Method Details
-
encode
This method hashes the provided rawPassword using BCrypt and returns the encoded password.- Parameters:
rawPassword
- Specifies the plain text password to be encoded.- Returns:
- The encoded password.
-
matches
This method checks if the provided rawPassword matches the encodedPassword using BCrypt.- Parameters:
rawPassword
- Specifies the plain text password to be encoded.encodedPassword
- Specifies the encoded password.- Returns:
- true, if the passwords match, false otherwise.
-