Skip to content

Commit ed6a7f7

Browse files
committed
Remove deprecated constructors in PasswordEncoders
Closes gh-11985
1 parent 7af111c commit ed6a7f7

File tree

5 files changed

+4
-76
lines changed

5 files changed

+4
-76
lines changed

Diff for: crypto/src/main/java/org/springframework/security/crypto/argon2/Argon2PasswordEncoder.java

-10
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,6 @@ public class Argon2PasswordEncoder implements PasswordEncoder {
6868

6969
private final BytesKeyGenerator saltGenerator;
7070

71-
/**
72-
* Constructs an Argon2 password encoder with a salt length of 16 bytes, a hash length
73-
* of 32 bytes, parallelism of 1, memory cost of 1 << 12 and 3 iterations.
74-
* @deprecated Use {@link #defaultsForSpringSecurity_v5_2()} instead
75-
*/
76-
@Deprecated
77-
public Argon2PasswordEncoder() {
78-
this(16, 32, 1, 1 << 12, 3);
79-
}
80-
8171
/**
8272
* Constructs an Argon2 password encoder with the provided parameters.
8373
* @param saltLength the salt length (in bytes)

Diff for: crypto/src/main/java/org/springframework/security/crypto/password/Pbkdf2PasswordEncoder.java

-52
Original file line numberDiff line numberDiff line change
@@ -85,58 +85,6 @@ public class Pbkdf2PasswordEncoder implements PasswordEncoder {
8585

8686
private boolean encodeHashAsBase64;
8787

88-
/**
89-
* Constructs a PBKDF2 password encoder with no additional secret value. There will be
90-
* a salt length of 8 bytes, 185,000 iterations, SHA-1 algorithm and a hash length of
91-
* 256 bits. The default is based upon aiming for .5 seconds to validate the password
92-
* when this class was added. Users should tune password verification to their own
93-
* systems.
94-
* @deprecated Use {@link #defaultsForSpringSecurity_v5_5()} instead
95-
*/
96-
@Deprecated
97-
public Pbkdf2PasswordEncoder() {
98-
this("");
99-
}
100-
101-
/**
102-
* Constructs a PBKDF2 password encoder with a secret value which is also included in
103-
* the password hash. There will be a salt length of 8 bytes, 185,000 iterations,
104-
* SHA-1 algorithm and a hash length of 256 bits.
105-
* @param secret the secret key used in the encoding process (should not be shared)
106-
* @deprecated Use {@link #Pbkdf2PasswordEncoder(CharSequence, int, int, int)} instead
107-
*/
108-
@Deprecated
109-
public Pbkdf2PasswordEncoder(CharSequence secret) {
110-
this(secret, 8);
111-
}
112-
113-
/**
114-
* Constructs a PBKDF2 password encoder with a secret value as well as salt length.
115-
* There will be 185,000 iterations, SHA-1 algorithm and a hash length of 256 bits.
116-
* @param secret the secret
117-
* @param saltLength the salt length (in bytes)
118-
* @since 5.5
119-
* @deprecated Use {@link #Pbkdf2PasswordEncoder(CharSequence, int, int, int)} instead
120-
*/
121-
@Deprecated
122-
public Pbkdf2PasswordEncoder(CharSequence secret, int saltLength) {
123-
this(secret, saltLength, 185000, 256);
124-
}
125-
126-
/**
127-
* Constructs a PBKDF2 password encoder with a secret value as well as iterations and
128-
* hash width. The salt length will be 8 bytes.
129-
* @param secret the secret
130-
* @param iterations the number of iterations. Users should aim for taking about .5
131-
* seconds on their own system.
132-
* @param hashWidth the size of the hash (in bits)
133-
* @deprecated Use {@link #Pbkdf2PasswordEncoder(CharSequence, int, int, int)} instead
134-
*/
135-
@Deprecated
136-
public Pbkdf2PasswordEncoder(CharSequence secret, int iterations, int hashWidth) {
137-
this(secret, 8, iterations, hashWidth);
138-
}
139-
14088
/**
14189
* Constructs a PBKDF2 password encoder with a secret value as well as salt length,
14290
* iterations and hash width.

Diff for: crypto/src/main/java/org/springframework/security/crypto/scrypt/SCryptPasswordEncoder.java

-10
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,6 @@ public class SCryptPasswordEncoder implements PasswordEncoder {
8080

8181
private final BytesKeyGenerator saltGenerator;
8282

83-
/**
84-
* Constructs a SCrypt password encoder with cpu cost of 16,384, memory cost of 8,
85-
* parallelization of 1, a key length of 32 and a salt length of 64 bytes.
86-
* @deprecated Use {@link #defaultsForSpringSecurity_v4_1()} instead
87-
*/
88-
@Deprecated
89-
public SCryptPasswordEncoder() {
90-
this(16384, 8, 1, 32, 64);
91-
}
92-
9383
/**
9484
* Constructs a SCrypt password encoder with the provided parameters.
9585
* @param cpuCost cpu cost of the algorithm (as defined in scrypt this is N). must be

Diff for: crypto/src/test/java/org/springframework/security/crypto/argon2/Argon2PasswordEncoderTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void encodeWhenRanTwiceWithCustomParamsThenNotEquals() {
8989
@Test
9090
public void matchesWhenGeneratedWithDifferentEncoderThenTrue() {
9191
Argon2PasswordEncoder oldEncoder = new Argon2PasswordEncoder(20, 64, 4, 256, 4);
92-
Argon2PasswordEncoder newEncoder = new Argon2PasswordEncoder();
92+
Argon2PasswordEncoder newEncoder = Argon2PasswordEncoder.defaultsForSpringSecurity_v5_2();
9393
String password = "secret";
9494
String oldEncodedPassword = oldEncoder.encode(password);
9595
assertThat(newEncoder.matches(password, oldEncodedPassword)).isTrue();

Diff for: crypto/src/test/java/org/springframework/security/crypto/password/Pbkdf2PasswordEncoderTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828

2929
public class Pbkdf2PasswordEncoderTests {
3030

31-
private Pbkdf2PasswordEncoder encoder = new Pbkdf2PasswordEncoder("secret");
31+
private Pbkdf2PasswordEncoder encoder = new Pbkdf2PasswordEncoder("secret", 8, 185000, 256);
3232

33-
private Pbkdf2PasswordEncoder encoderSalt16 = new Pbkdf2PasswordEncoder("", 16);
33+
private Pbkdf2PasswordEncoder encoderSalt16 = new Pbkdf2PasswordEncoder("", 16, 185000, 256);
3434

3535
private Pbkdf2PasswordEncoder[] encoders = new Pbkdf2PasswordEncoder[] { this.encoder, this.encoderSalt16 };
3636

@@ -221,7 +221,7 @@ private void run(int iterations, int count) {
221221
long avg = 0;
222222
while (avg < HALF_SECOND) {
223223
iterations += 10000;
224-
Pbkdf2PasswordEncoder encoder = new Pbkdf2PasswordEncoder("", iterations, 256);
224+
Pbkdf2PasswordEncoder encoder = new Pbkdf2PasswordEncoder("", 8, iterations, 256);
225225
String encoded = encoder.encode("password");
226226
System.out.println("Trying " + iterations);
227227
long start = System.currentTimeMillis();

0 commit comments

Comments
 (0)