Description
A storage leak exposes plaintext passwords immediately. Fast hashes such as MD5, SHA-1 and plain SHA-256 make it cheap to compare password guesses against leaked hashes.
Potential impact
Unauthorized access
An exposed password can let someone sign in as the user, read personal data or make fraudulent payments.
Credential reuse
Other accounts may be exposed if the user reused the password.
Legal and regulatory requirements
Inadequate storage may violate applicable data-protection requirements and damage customer trust.
Remediation
- Prefer Argon2id for new systems. For existing bcrypt or PBKDF2 implementations, benchmark the server and set an adequate work factor.
- Generate a fresh random salt for each password and store it with the hash. This limits reuse of precomputed results across accounts.
- If FIPS-140 applies, use PBKDF2-HMAC-SHA256 in a validated cryptographic module, with at least 600,000 iterations as the baseline.
Examples
Before
These excerpts use the Spring Security 5.8 JDBC configuration style. They assume a schema that returns the username, password hash, and enabled status in the required order.
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth, DataSource dataSource) throws Exception {
auth.jdbcAuthentication()
.dataSource(dataSource)
.usersByUsernameQuery("SELECT * FROM users WHERE username = ?")
.passwordEncoder(new StandardPasswordEncoder()); // Weak password hashing
}
After
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth, DataSource dataSource) throws Exception {
auth.jdbcAuthentication()
.dataSource(dataSource)
.usersByUsernameQuery("SELECT * FROM users WHERE username = ?")
.passwordEncoder(new BCryptPasswordEncoder()); // Use bcrypt with an adjustable work factor
}
The legacy StandardPasswordEncoder uses a salt and only 1,024 SHA-256 iterations. When moving to BCryptPasswordEncoder, check input-length limits and performance. For migration at login, keep the legacy verifier and hash the submitted password with bcrypt after legacy verification succeeds. Otherwise, require a password reset.
References
- CWE-256 — plaintext password storage
- CWE-916 — insufficient password-hashing effort
- OWASP Password Storage Cheat Sheet
- Spring Security BCryptPasswordEncoder documentation
- Spring Security 5.8.16
StandardPasswordEncoder