Package rs.baselib.crypto
Class CombinedPasswordHasher
java.lang.Object
rs.baselib.crypto.CombinedPasswordHasher
- All Implemented Interfaces:
PasswordHasher
public class CombinedPasswordHasher extends java.lang.Object implements PasswordHasher
Implements a combined strategy to hash passwords.
The object will use a default ExtendedPasswordHasher in order
to create hashes but will use all defined hashers to test a given password hash.
- Since:
- 1.2.9
- Author:
- ralph
- See Also:
ExtendedPasswordHasher
-
Field Summary
Fields Modifier and Type Field Description static PasswordHasherUNIX_STRATEGY_BLOWFISHA UNIX strategy to hash and check passwords (withBlowfishPasswordHasheras default).static PasswordHasherUNIX_STRATEGY_MD5A UNIX strategy to hash and check passwords (withMd5PasswordHasheras default).static PasswordHasherUNIX_STRATEGY_PHPA UNIX strategy to hash and check passwords (withPhpPasswordHasheras default).static PasswordHasherUNIX_STRATEGY_SHA256A UNIX strategy to hash and check passwords (withMd5PasswordHasheras default).static PasswordHasherUNIX_STRATEGY_SHA512A UNIX strategy to hash and check passwords (withMd5PasswordHasheras default). -
Constructor Summary
Constructors Constructor Description CombinedPasswordHasher(ExtendedPasswordHasher... passwordHashers)Constructor. -
Method Summary
Modifier and Type Method Description ExtendedPasswordHashergetDefaultPasswordHasher()Returns the default password hasher, that is the hasher used for hashing passwords.java.lang.StringgetPasswordHash(java.lang.String plainPassword)Returns a hash of the given plain password.ExtendedPasswordHasher[]getPasswordHashers()Returns the password hashers used.booleantestPassword(java.lang.String plainPassword, java.lang.String passwordHash)Tests a plain Password whether it is the same as a previously hashed password.
-
Field Details
-
UNIX_STRATEGY_MD5
A UNIX strategy to hash and check passwords (withMd5PasswordHasheras default).This instance used (in order of check):
-
UNIX_STRATEGY_BLOWFISH
A UNIX strategy to hash and check passwords (withBlowfishPasswordHasheras default).This instance used (in order of check):
-
UNIX_STRATEGY_PHP
A UNIX strategy to hash and check passwords (withPhpPasswordHasheras default).This instance used (in order of check):
-
UNIX_STRATEGY_SHA512
A UNIX strategy to hash and check passwords (withMd5PasswordHasheras default).This instance used (in order of check):
-
UNIX_STRATEGY_SHA256
A UNIX strategy to hash and check passwords (withMd5PasswordHasheras default).This instance used (in order of check):
-
-
Constructor Details
-
CombinedPasswordHasher
Constructor.- Parameters:
passwordHashers- the list of hash algorithms to be used. the first algorithm will be used for hashing a password (default hasher).
-
-
Method Details
-
getPasswordHash
public java.lang.String getPasswordHash(java.lang.String plainPassword)Returns a hash of the given plain password.- Specified by:
getPasswordHashin interfacePasswordHasher- Parameters:
plainPassword- the password to be hashed- Returns:
- the hash of the password
-
testPassword
public boolean testPassword(java.lang.String plainPassword, java.lang.String passwordHash)Tests a plain Password whether it is the same as a previously hashed password.- Specified by:
testPasswordin interfacePasswordHasher- Parameters:
plainPassword- the plain password to be checkedpasswordHash- the hash of another password- Returns:
truewhen both passwords match each other
-
getPasswordHashers
Returns the password hashers used.- Returns:
- the password hashers
-
getDefaultPasswordHasher
Returns the default password hasher, that is the hasher used for hashing passwords.- Returns:
- the default password hasher
-