mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-23 04:22:17 +00:00
BCryptPasswordEncoder rawPassword cannot be null
Closes gh-8317
This commit is contained in:
parent
24d251f232
commit
c2296b0376
@ -65,6 +65,10 @@ public class BCryptPasswordEncoder implements PasswordEncoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String encode(CharSequence rawPassword) {
|
public String encode(CharSequence rawPassword) {
|
||||||
|
if (rawPassword == null) {
|
||||||
|
throw new IllegalArgumentException("rawPassword cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
String salt;
|
String salt;
|
||||||
if (strength > 0) {
|
if (strength > 0) {
|
||||||
if (random != null) {
|
if (random != null) {
|
||||||
@ -81,6 +85,10 @@ public class BCryptPasswordEncoder implements PasswordEncoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean matches(CharSequence rawPassword, String encodedPassword) {
|
public boolean matches(CharSequence rawPassword, String encodedPassword) {
|
||||||
|
if (rawPassword == null) {
|
||||||
|
throw new IllegalArgumentException("rawPassword cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
if (encodedPassword == null || encodedPassword.length() == 0) {
|
if (encodedPassword == null || encodedPassword.length() == 0) {
|
||||||
logger.warn("Empty encoded password");
|
logger.warn("Empty encoded password");
|
||||||
return false;
|
return false;
|
||||||
|
@ -92,4 +92,15 @@ public class BCryptPasswordEncoderTests {
|
|||||||
assertThat(encoder.matches("password", "012345678901234567890123456789")).isFalse();
|
assertThat(encoder.matches("password", "012345678901234567890123456789")).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void encodeNullRawPassword() {
|
||||||
|
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
|
||||||
|
encoder.encode(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void matchNullRawPassword() {
|
||||||
|
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
|
||||||
|
encoder.matches(null, "does-not-matter");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user