Class PasswordHasher

java.lang.Object
com.revetsec.password.PasswordHasher

@ThreadSafe public final class PasswordHasher extends Object
Standalone, caller-thread password hashing. New hashes are Argon2id v19; legacy bcrypt and PBKDF2 verification are separate, opt-in operations selected by trusted account provenance. Applications own account lookup, per-account online admission, password policy, credential persistence, credential-version checks, rehash compare-and-swap, and login sessions/MFA.

Instances are safe to share across threads when their supplied work gate and pepper source are shared and thread-safe. No operation starts a worker thread. A pepper-enabled instance requires its peppered native stored form and never falls back to an unpeppered PHC value. One work permit covers preparation, pepper lookup and KDF cleanup. NFC uses the running JDK's Unicode data; stored forms do not identify that preparation revision. Applications own trusted credential preparation cohorts and verified migration between them.

Since:
1.0.0
  • Method Details

    • withArgon2id

      Starts configuration with the required new-hash policy. Construction performs no crypto, random-source, provider, storage, or network work.
      Parameters:
      parameters - Argon2id v19 creation parameters
      Returns:
      a builder
      Since:
      1.0.0
    • hashResult

      @CheckReturnValue public @NonNull PasswordHashResult hashResult(char @NonNull [] password)
      Hashes a new password after bounded NFC/strict-UTF-8 preparation. The input array is borrowed and never modified or retained; the caller must clear it when finished. No minimum password-strength policy is implied by successful hashing.
      Parameters:
      password - complete submitted password
      Returns:
      a new stored verifier, rejection, or unavailability
      Since:
      1.0.0
    • verifyResult

      @CheckReturnValue public @NonNull PasswordVerificationResult verifyResult(char @NonNull [] password, @NonNull String storedForm)
      Verifies only a native Argon2id stored form under this deployment's pepper policy. It parses and caps encoded length, costs, salt and tag before allocating KDF memory.
      Parameters:
      password - complete submitted password; borrowed and not modified
      storedForm - account-owned stored verifier
      Returns:
      a complete verification outcome
      Since:
      1.0.0
    • verifyLegacyBcryptResult

      @CheckReturnValue public @NonNull PasswordVerificationResult verifyLegacyBcryptResult(char @NonNull [] password, @NonNull String storedForm)
      Verifies one explicitly selected historical bcrypt record. The application must select this operation from trusted account provenance; no stored hash auto-selects a legacy path. Candidates exceeding bcrypt's 72-byte input limit are rejected without truncation.
      Parameters:
      password - submitted password; borrowed and not modified
      storedForm - historical modular-crypt bcrypt value
      Returns:
      a complete verification outcome; every match recommends Argon2id rehash
      Since:
      1.0.0
    • verifyLegacyPbkdf2Result

      @CheckReturnValue public @NonNull PasswordVerificationResult verifyLegacyPbkdf2Result(char @NonNull [] password, @NonNull Pbkdf2Hmac hmac, @NonNull Integer iterations, byte @NonNull [] salt, byte @NonNull [] expectedTag)
      Verifies one historical PBKDF2 record whose fields the application extracted from its trusted legacy schema. No generic PBKDF2 string parser or format autodetection is provided.
      Parameters:
      password - submitted password; borrowed and not modified
      hmac - historical HMAC algorithm
      iterations - historical iteration count
      salt - historical salt; borrowed and not modified
      expectedTag - historical derived value; borrowed and not modified
      Returns:
      a complete verification outcome; every match recommends Argon2id rehash
      Since:
      1.0.0