Class Pbkdf2PasswordHasher
java.lang.Object
com.svenruppert.jsentinel.authentication.Pbkdf2PasswordHasher
- All Implemented Interfaces:
PasswordHasher
PBKDF2-HMAC-SHA256 hasher using only JDK APIs. Encoded format:
pbkdf2$<iterations>$<base64-salt>$<base64-hash>.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringAlgorithm identifier exposed byPasswordHash.algorithm().static final StringParameter key — iteration count.static final StringParameter key — base64-encoded salt. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionhash(char[] rawPassword) Hashes the password and returns the implementation's wire format.booleanneedsRehash(PasswordHash storedHash) Reports whetherstoredHashwas produced with parameters that differ from this hasher's current configuration.Parses a wire-format hash into aPasswordHash.serialize(PasswordHash hash) Inverse ofPasswordHasher.parse(String).booleanVerifies a candidate password against a wire-format stored hash.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface PasswordHasher
hashTo, needsRehash, verifyModifier and TypeMethodDescriptiondefault PasswordHashhashTo(char[] rawPassword) Hashes the password and returns the parsedPasswordHash(algorithm + encoded bytes + parameters).default booleanneedsRehash(String storedHash) Convenience: parsesstoredHashviaPasswordHasher.parse(String)and delegates toPasswordHasher.needsRehash(PasswordHash).default booleanverify(char[] rawPassword, PasswordHash storedHash) Verifies a candidate password against a typedPasswordHash.
-
Field Details
-
ALGORITHM_ID
Algorithm identifier exposed byPasswordHash.algorithm().- See Also:
-
PARAM_ITERATIONS
-
PARAM_SALT
-
-
Constructor Details
-
Pbkdf2PasswordHasher
public Pbkdf2PasswordHasher() -
Pbkdf2PasswordHasher
-
-
Method Details
-
hash
Description copied from interface:PasswordHasherHashes the password and returns the implementation's wire format.- Specified by:
hashin interfacePasswordHasher
-
verify
Description copied from interface:PasswordHasherVerifies a candidate password against a wire-format stored hash.- Specified by:
verifyin interfacePasswordHasher
-
parse
Description copied from interface:PasswordHasherParses a wire-format hash into aPasswordHash. Implementations that override the typed API must override this method too. Default throws — the default implementations ofPasswordHasher.hashTo(char[])andPasswordHasher.verify(char[], PasswordHash)call this, so a hasher that provides only theStringpair must override either the default methods or this one to participate in the typed API.- Specified by:
parsein interfacePasswordHasher- Parameters:
storedHash- wire-format hash- Returns:
- parsed typed hash
-
serialize
Description copied from interface:PasswordHasherInverse ofPasswordHasher.parse(String). Default throws.- Specified by:
serializein interfacePasswordHasher- Parameters:
hash- typed hash- Returns:
- wire-format string suitable for
PasswordHasher.verify(char[], String)
-
needsRehash
Description copied from interface:PasswordHasherReports whetherstoredHashwas produced with parameters that differ from this hasher's current configuration. Callers that want to upgrade weak or outdated hashes should re-hash on the next successful login when this returnstrue.The default returns
false(no drift detection). Concrete implementations likePbkdf2PasswordHashercompare the hash's algorithm + iteration count against their own.- Specified by:
needsRehashin interfacePasswordHasher- Parameters:
storedHash- previously stored hash; nevernull- Returns:
truewhenstoredHashis a pbkdf2 hash whose iteration count differs from this hasher's currentiterations, or when its algorithm is not pbkdf2 at all (in which case re-hashing migrates the user to the current scheme on the next successful login).
-