Spring Security - user authentication with BCrypt hashed password (bad credentials error)
<p>After registration of a new user, generated hashed password in database don't match password from user input typed in order to authenticate. Raw passwords are the same but hashed versions are different. I wonder how to get these two match each other for proper authentication? I'm using Spring 4.3.2.RELEASE, and 4.2.0.RELEASE for Security.</p>

<p>Also I have a warning:</p>

<pre><code>WARN SpringSecurityCoreVersion:78 - **** You are advised to use Spring 4.3.4.RELEASE or later with this version. You are running: 4.3.0.RELEASE
</code></pre>

<p>Maybe this is causing a problem in some way.</p>

<p>config.xml:</p>

<pre><code>&lt;bean id="encoder" class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder" /&gt;

&lt;security:authentication-manager&gt;
    &lt;security:authentication-provider user-service-ref="userService"&gt;
        &lt;security:password-encoder ref="encoder"/&gt;
    &lt;/security:authentication-provider&gt;
&lt;/security:authentication-manager&gt;

&lt;bean id="daoAuthenticationProvider" class="org.springframework.security.authentication.dao.DaoAuthenticationProvider"&gt;
    &lt;property name="userDetailsService" ref="userService" /&gt;
    &lt;property name="hideUserNotFoundExceptions" value="false" /&gt;
    &lt;property name="passwordEncoder" ref="encoder" /&gt;
&lt;/bean&gt;

&lt;bean id="authenticationManager" class="org.springframework.security.authentication.ProviderManager"&gt;
    &lt;constructor-arg&gt;
        &lt;ref bean="daoAuthenticationProvider" /&gt;
    &lt;/constructor-arg&gt;
&lt;/bean&gt;
</code></pre>

<p>UserEntity.java:</p>

<pre><code>public void setPassword(String password) {
    BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
    this.password = passwordEncoder.encode(password);
}
</code></pre>

<p>UserAuthenticationProviderService.java:</p>

<pre><code>public boolean processUserAuthentication(UserEntity user) {

    try {
        Authentication request = new UsernamePasswordAuthenticationToken(user.getUserName(), user.getPassword());
        Authentication result = authenticationManager.authenticate(request);
        SecurityContextHolder.getContext().setAuthentication(result);

        return true;
    } catch(AuthenticationException e) {
        FacesContext.getCurrentInstance().addMessage(null, 
                new FacesMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), "Catched Error!"));

        return false;
    }
}
</code></pre>

<p>EDIT: Solved.</p>

<p>As Shaun said problem was encoding in Entity class. After moving encoding to place of user creation everything works well, because encoding now appears only in user creation process. Thanks!</p>