Interface PasswordHasher

All Known Implementing Classes:
Pbkdf2PasswordHasher

public interface PasswordHasher
Password hashing abstraction. The bootstrap service hashes the raw administrator password before handing it to the application's AdministratorAccountStore. Plaintext passwords are never stored.

Two parallel APIs are exposed:

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 Details

    • hash

      String hash(char[] rawPassword)
      Hashes the password and returns the implementation's wire format.
    • verify

      boolean verify(char[] rawPassword, String storedHash)
      Verifies a candidate password against a wire-format stored hash.
    • hashTo

      default PasswordHash hashTo(char[] rawPassword)
      Hashes the password and returns the parsed PasswordHash (algorithm + encoded bytes + parameters). The default implementation delegates to hash(char[]) and parses the result via parse(String).
      Parameters:
      rawPassword - cleared by the caller; the hasher must not retain it
      Returns:
      typed hash
    • verify

      default boolean verify(char[] rawPassword, PasswordHash storedHash)
      Verifies a candidate password against a typed PasswordHash. Default delegates to verify(char[], String) via serialize(PasswordHash).
      Parameters:
      rawPassword - candidate
      storedHash - previously stored hash
      Returns:
      true if the candidate matches
    • needsRehash

      default boolean needsRehash(PasswordHash storedHash)
      Reports whether storedHash was 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 returns true.

      The default returns false (no drift detection). Concrete implementations like Pbkdf2PasswordHasher compare the hash's algorithm + iteration count against their own.

      Parameters:
      storedHash - previously stored hash; never null
      Returns:
      true when a re-hash is recommended
    • needsRehash

      default boolean needsRehash(String storedHash)
      Convenience: parses storedHash via parse(String) and delegates to needsRehash(PasswordHash).

      Returns false for null input or when the hasher cannot parse the stored format (UnsupportedOperationException from the default parse, or any IllegalArgumentException the 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 be null
      Returns:
      true when a re-hash is recommended
    • parse

      default PasswordHash parse(String storedHash)
      Parses a wire-format hash into a PasswordHash. Implementations that override the typed API must override this method too. Default throws — the default implementations of hashTo(char[]) and verify(char[], PasswordHash) call this, so a hasher that provides only the String pair 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

      default String serialize(PasswordHash hash)
      Inverse of parse(String). Default throws.
      Parameters:
      hash - typed hash
      Returns:
      wire-format string suitable for verify(char[], String)