Interface PasswordHasher
- All Known Implementing Classes:
Pbkdf2PasswordHasher
AdministratorAccountStore.
Plaintext passwords are never stored.
Two parallel APIs are exposed:
- The original
String-based pair (hash(char[])/verify(char[], String)) — used by callers that persist the hash as a single opaque string. - A typed pair (
hashTo(char[])/verify(char[], PasswordHash)/needsRehash(PasswordHash)) — used by callers that want to inspect algorithm parameters or detect drift between the hasher's current parameters and an existing stored hash.
Default implementations bridge between the two views via a hasher's own wire format, so applications can pick whichever shape fits their persistence layer without forcing a second SPI.
-
Method Summary
Modifier and TypeMethodDescriptionhash(char[] rawPassword) Hashes the password and returns the implementation's wire format.default PasswordHashhashTo(char[] rawPassword) Hashes the password and returns the parsedPasswordHash(algorithm + encoded bytes + parameters).default booleanneedsRehash(PasswordHash storedHash) Reports whetherstoredHashwas produced with parameters that differ from this hasher's current configuration.default booleanneedsRehash(String storedHash) default PasswordHashParses a wire-format hash into aPasswordHash.default Stringserialize(PasswordHash hash) Inverse ofparse(String).default booleanverify(char[] rawPassword, PasswordHash storedHash) Verifies a candidate password against a typedPasswordHash.booleanVerifies a candidate password against a wire-format stored hash.
-
Method Details
-
hash
Hashes the password and returns the implementation's wire format. -
verify
Verifies a candidate password against a wire-format stored hash. -
hashTo
Hashes the password and returns the parsedPasswordHash(algorithm + encoded bytes + parameters). The default implementation delegates tohash(char[])and parses the result viaparse(String).- Parameters:
rawPassword- cleared by the caller; the hasher must not retain it- Returns:
- typed hash
-
verify
Verifies a candidate password against a typedPasswordHash. Default delegates toverify(char[], String)viaserialize(PasswordHash).- Parameters:
rawPassword- candidatestoredHash- previously stored hash- Returns:
trueif the candidate matches
-
needsRehash
Reports 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.- Parameters:
storedHash- previously stored hash; nevernull- Returns:
truewhen a re-hash is recommended
-
needsRehash
Convenience: parsesstoredHashviaparse(String)and delegates toneedsRehash(PasswordHash).Returns
falsefornullinput or when the hasher cannot parse the stored format (UnsupportedOperationExceptionfrom the defaultparse, or anyIllegalArgumentExceptionthe implementation may raise on malformed input). Failure to parse is not an error worth aborting the login flow over — the caller already has a successfully verified hash, so the worst case is "we couldn't upgrade it on this login".- Parameters:
storedHash- wire-format stored hash, may benull- Returns:
truewhen a re-hash is recommended
-
parse
Parses a wire-format hash into aPasswordHash. Implementations that override the typed API must override this method too. Default throws — the default implementations ofhashTo(char[])andverify(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.- Parameters:
storedHash- wire-format hash- Returns:
- parsed typed hash
-
serialize
Inverse ofparse(String). Default throws.- Parameters:
hash- typed hash- Returns:
- wire-format string suitable for
verify(char[], String)
-