← Java / Spring · Contents

JAVA-042 / Beginner

Hashing passwords with MessageDigest (MD5/SHA-1)

A02:2021 Cryptographic Failures · CWE-328 Reversible/Weak Hash · CWE-759 Unsalted

Why is this a problem?

Vulnerable to GPU guessing attacks and lacks a salt.

How to fix it

java
PasswordEncoder enc = PasswordEncoderFactories.createDelegatingPasswordEncoder();  // bcrypt by default
String hash = enc.encode(rawPassword);

Further reading