Answer the question
In order to leave comments, you need to log in
How does matches from BCryptPasswordEncoder.class java work?
Hello everyone, digging into BCryptPasswordEncoder some point is not clear to me, namely:
Example
@Test
public void matchesTwoPassTest() {
boolean resultOne = false;
boolean resultTwo = false;
boolean resultThree = false;
String one = "alex";
String two = "alex";
String three = "alex";
String oneEnc = "";
String twoEnc = "";
oneEnc = bCryptPasswordEncoder.encode(one);
twoEnc = bCryptPasswordEncoder.encode(two);
resultOne = bCryptPasswordEncoder.matches(two, oneEnc);
resultTwo = bCryptPasswordEncoder.matches(one, twoEnc);
resultThree = bCryptPasswordEncoder.matches(three, twoEnc);
logger.debug(one + " ONE ENCODE STRING " + oneEnc);
logger.debug(two + " TWO ENCODE STRING " + twoEnc);
logger.debug("result : " + resultOne);
logger.debug("result : " + resultTwo);
assertTrue(resultOne);
assertTrue(resultTwo);
assertTrue(resultThree);
}
Answer the question
In order to leave comments, you need to log in
According to the documentation, the encoder accepts an 8-byte random salt. It has no effect on the matcher.
Apparently that's how it's meant to be.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question