title: User login fails when using password encoding in Spring
body: <p>I am using Spring <code>StandardPasswordEncoder</code> to encode password before inserting into database. But when trying to login with same password I am getting an invalid password error. Not sure what is wrong. Below is the code.</p>
  
  <p>security configuration:</p>
  
  <pre><code>&lt;security:authentication-manager id="authMgr"&gt;
      &lt;security:authentication-provider&gt;
          &lt;security:jdbc-user-service
              data-source-ref="dataSource" /&gt;
          &lt;security:password-encoder ref="passwordEncoder"&gt;&lt;/security:password-encoder&gt;
      &lt;/security:authentication-provider&gt;
  &lt;/security:authentication-manager&gt;
  &lt;bean id="passwordEncoder   class="org.springframework.security.crypto.password.StandardPasswordEncoder"&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>Service layer(password encoding before passing data to data access layer)</p>
  
  <pre><code>import org.springframework.security.crypto.password.PasswordEncoder;
  
  @Autowired
  private PasswordEncoder passwordEncoder;
  
  user.setPassword(passwordEncoder.encode(newAccountDetails.getPassword()));
  userDataAccess.createUser(user);
  </code></pre>