Why AI tools produce this: AI coding tools generate this anti-pattern by default, it appears in a large share of AI-written auth code.
Why this matters
These algorithms are designed to be fast, which makes offline brute-force and rainbow-table attacks cheap. They are NOT suitable for storing passwords (CWE-916).
Use a dedicated, slow password-hashing function with a per-password salt and a tunable work factor: BCrypt (BCryptPasswordEncoder), Argon2 (Argon2PasswordEncoder), or PBKDF2 (Pbkdf2PasswordEncoder / SecretKeyFactory with PBKDF2WithHmacSHA256). These resist brute-force by design.
import java.security.MessageDigest;import java.security.NoSuchAlgorithmException;import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;import org.springframework.security.crypto.argon2.Argon2PasswordEncoder;class SafePasswordHash { // ok: auth.java.crypto.weak-password-hash -- BCrypt is a proper password hasher String bcrypt(String password) { return new BCryptPasswordEncoder().encode(password); } // ok: auth.java.crypto.weak-password-hash -- Argon2 is a proper password hasher String argon2(String password) { return Argon2PasswordEncoder.defaultsForSpringSecurity_v5_8().encode(password); } // ok: auth.java.crypto.weak-password-hash -- SHA-256 over file bytes is a checksum, not a password byte[] fileChecksum(byte[] fileBytes) throws NoSuchAlgorithmException { MessageDigest md = MessageDigest.getInstance("SHA-256"); return md.digest(fileBytes); } // ok: auth.java.crypto.weak-password-hash -- non-password fingerprint byte[] contentFingerprint(String content) throws NoSuchAlgorithmException { MessageDigest md = MessageDigest.getInstance("SHA-256"); return md.digest(content.getBytes()); }}
Suppressing this rule
If a finding is a genuine false positive, scope the suppression to the exact line and leave a reason, never disable the rule project-wide. Disable directives are line-scoped by design.