spring-projects / spring-projects/spring-security

Support Parameter-Based Hash Matching for Password4j Encoders

Open
#17,882 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage type: enhancement
Dominant language
Java
Stars
9.6k
Forks
6.3k
Avg merge
2d 11h
Merged PRs (30d)
52

Description

The Password4j encoders should support matching passwords that were encoded with different parameters than the current encoder configuration. This can be achieved using Password4j's static getInstanceFromHash(String) methods that extract parameters from the encoded hash.

Affected Classes
BcryptPassword4jPasswordEncoder - supports BcryptFunction.getInstanceFromHash(String)
Argon2Password4jPasswordEncoder - supports Argon2Function.getInstanceFromHash(String)
ScryptPassword4jPasswordEncoder - supports ScryptFunction.getInstanceFromHash(String)

Current Limitation
Currently, these encoders can only match passwords that were encoded with the exact same parameters as the current encoder configuration.

Expected Enhancement
Enhance the matchesNonNull method to extract algorithm parameters from the encoded password hash and use those parameters for matching, allowing passwords encoded with different parameters to be validated correctly.

Note
Not all Password4j implementations support parameter extraction from hashes:
✅ BCrypt, Argon2, SCrypt - support getInstanceFromHash(String)
❌ PBKDF2, Balloon Hashing - do not include parameters in the hash format used by Password4j

Implementation Approach
For supported algorithms, modify the matching logic to:
Try matching with current encoder configuration first (for performance)
If that fails, extract parameters from the hash using getInstanceFromHash(String)
Use the extracted function for matching

Related #17825

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with matchesNonNull in BcryptPassword4jPasswordEncoder, Argon2Password4jPasswordEncoder, and ScryptPassword4jPasswordEncoder, then review the corresponding Password4j getInstanceFromHash(String) methods. Done means hashes created with different supported parameters match correctly, while PBKDF2 and Balloon Hashing remain unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
authentication, security
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.