Package com.alpaca.security.manager
Class PasswordManager
java.lang.Object
com.alpaca.security.manager.PasswordManager
Spring component responsible for handling secure password hashing and verification using PBKDF2.
It wraps a configured
Pbkdf2PasswordEncoder
to encode raw passwords and validate matches.
The encoder is configured via application property spring.datasource.secret.key
, which
serves as the "pepper" — an application-wide secret added on top of per-password salts for
enhanced security. (Pbkdf2PasswordEncoder
)
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final org.springframework.security.crypto.password.Pbkdf2PasswordEncoder
-
Constructor Summary
ConstructorsConstructorDescriptionPasswordManager
(String secretKey) Constructs aPasswordManager
using a secret key as "pepper". -
Method Summary
Modifier and TypeMethodDescriptionencodePassword
(String rawPassword) Encodes a raw password using PBKDF2 hashing.boolean
Validates a raw password against a previously hashed password.org.springframework.security.crypto.password.PasswordEncoder
Exposes the underlyingPasswordEncoder
.
-
Field Details
-
encoder
private final org.springframework.security.crypto.password.Pbkdf2PasswordEncoder encoder
-
-
Constructor Details
-
PasswordManager
Constructs aPasswordManager
using a secret key as "pepper". The encoder is initialized with the following properties:- Salt length: 16 bytes (default for Spring Security 5.8+)
- Iterations: 310,000 (default aiming for ~0.5 seconds processing time)
- Algorithm: PBKDF2WithHmacSHA512
- Output encoding: Base64 (instead of hex)
- Parameters:
secretKey
- the application-wide secret ("pepper") to enhance password hashing security; must not benull
-
-
Method Details
-
passwordEncoder
public org.springframework.security.crypto.password.PasswordEncoder passwordEncoder()Exposes the underlyingPasswordEncoder
. Useful when integration with Spring Security configurations is needed.- Returns:
- the configured
PasswordEncoder
-
encodePassword
Encodes a raw password using PBKDF2 hashing.- Parameters:
rawPassword
- the plain text password- Returns:
- the hashed password string
-
matches
Validates a raw password against a previously hashed password.- Parameters:
rawPassword
- the plain text password to validateencodedPassword
- the stored hashed password- Returns:
true
if the raw password matches the encoded one;false
otherwise
-