title: Why BCryptPasswordEncoder from Spring generate different outputs for same input?
body: <p>I am using <a href="https://docs.spring.io/spring-security/site/docs/current/api/org/springframework/security/crypto/bcrypt/BCryptPasswordEncoder.html" rel="noreferrer">BCryptPasswordEncoder</a> with Spring security. My expectation was that for the same input I will always get the same output. But for the same input I get different output. You could test it with the code snippet below:</p>
  
  <pre><code>String password = "123456"; 
  PasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); 
  String encodedPassword = passwordEncoder.encode(password);
  System.out.print(encodedPassword);
  </code></pre>
  
  <blockquote>
    <p>output: $2a$10$cYLM.qoXpeAzcZhJ3oXRLu9Slkb61LHyWW5qJ4QKvHEMhaxZ5qCPi</p>
    
    <p>output2: $2a$10$KEvYX9yjj0f1X3Wl8S.KPuWzSWGyGM9ubI71NOm3ZNbJcwWN6agvW</p>
    
    <p>output3: $2a$10$nCmrPtUaOLn5EI73VZ4Ouu1TmkSWDUxxD4N6A.8hPBWg43Vl.RLDC</p>
  </blockquote>
  
  <p>Could someone explain, why BCryptPasswordEncoder behave like this?</p>